package com.css.fxfzysx.modules.cztDataMange.service.impl;


import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.css.fxfzysx.base.response.RestResponse;
import com.css.fxfzysx.common.utils.BeanUtil;
import com.css.fxfzysx.common.utils.UpdateUtil;
import com.css.fxfzysx.constants.FxfzConstants;
import com.css.fxfzysx.constants.YNEnum;
import com.css.fxfzysx.modules.cztDataMange.constans.RedisKeyConstants;
import com.css.fxfzysx.modules.cztDataMange.entity.*;
import com.css.fxfzysx.modules.cztDataMange.excel.ExcelReaderPlus;
import com.css.fxfzysx.modules.cztDataMange.param.BuildingVulnerabilityParam;
import com.css.fxfzysx.modules.cztDataMange.param.ConfirmMoveIdParam;
import com.css.fxfzysx.modules.cztDataMange.param.MatrixParam;
import com.css.fxfzysx.modules.cztDataMange.param.MoveInParam;
import com.css.fxfzysx.modules.cztDataMange.repository.BacInformationRepository;
import com.css.fxfzysx.modules.cztDataMange.repository.RcpRepository;
import com.css.fxfzysx.modules.cztDataMange.service.BacInformationService;
import com.css.fxfzysx.modules.cztDataMange.utils.GenerationNumberUtil;
import com.css.fxfzysx.modules.cztDataMange.vo.*;
import com.css.fxfzysx.modules.vabStructure.constans.BuildingRoofEnum;
import com.css.fxfzysx.modules.vabStructure.constans.BuildingSeismicResistanceEnum;
import com.css.fxfzysx.modules.vabStructure.constans.CorrectionCiEnum;
import com.css.fxfzysx.modules.vabStructure.entity.CztBrickConcreteDestroyCalc;
import com.css.fxfzysx.modules.vabStructure.entity.CztBrickConcreteDestroyResult;
import com.css.fxfzysx.modules.vabStructure.param.CustomVulnerabilityParam;
import com.css.fxfzysx.modules.vabStructure.repository.*;
import com.css.fxfzysx.modules.vabStructure.repository.impl.CrsEntiretyCiRepository;
import com.css.fxfzysx.modules.vabStructure.service.SrcAnalyseService;
import com.css.fxfzysx.modules.vabStructure.service.impl.FshBuildingsServiceImpl;
import com.css.fxfzysx.modules.vabStructure.service.impl.PobStructureServiceImpl;
import com.css.fxfzysx.modules.vabStructure.utils.SrcAnaluseUtils;
import com.css.fxfzysx.modules.vaomeFacilities.service.impl.ImportDataServiceImpl;
import com.css.fxfzysx.modules.ysxManagement.entity.CStructureCiEntity;
import com.css.fxfzysx.modules.ysxManagement.entity.ZqtEntity;
import com.css.fxfzysx.modules.ysxManagement.repository.RcStructureRepository;
import com.css.fxfzysx.modules.ysxManagement.repository.ZqtCiRepository;
import com.css.fxfzysx.util.*;
import com.css.fxfzysx.web.PlatformSessionContext;
import com.css.fxfzysx.zcpt.sys.entity.SUser;
import com.css.fxfzysx.zcpt.sys.service.SUserService;
import com.css.fxfzysx.zcpt.sys.service.SysAreaService;
import com.google.gson.JsonSyntaxException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.stream.Collectors;

@Service
@Slf4j
public class BacInformationServiceImpl implements BacInformationService {

    @Autowired
    private BacInformationRepository bacInformationRepository;

    @Resource
    private GenerationNumberUtil generationNumberUtil;

    @Autowired
    private SUserService sUserService;
    @Autowired
    private CrsEntiretyCalResultRepository crsEntiretyCalResultRepository;

    @Autowired
    private CrsStoreyCalResultRespository crsStoreyCalResultRespository;

    @Autowired
    private SrcAnaluseUtils srcAnaluseUtils;

    @Autowired
    private FshBuildingsRepository fshBuildingsRepository;

    @Autowired
    private PobStructureRepository pobStructureRepository;

    @Autowired
    private RcpInformationRepository rcpInformationRepository;

    @Autowired
    private PsvAnalysisRepository psvAnalysisRepository;

    @Autowired
    private CustomVulnerabilityRepository customVulnerabilityRepository;

    @Autowired
    private CrsRoofbeamCalRepository roofbeamCalRepository;

    @Autowired
    private PobStructureServiceImpl pobStructureService;

    @Autowired
    private FshBuildingsServiceImpl fshBuildingsService;

    @Autowired
    private ZqtCiRepository zqtCiRepository;

    @Autowired
    private RcStructureRepository rcStructureRepository;

    @Override
    public RestResponse uploadBvInformation(MultipartFile file) {
        try {
            String user = sUserService.getSUser(PlatformSessionContext.getUserID());
            SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
            ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
            List<Object> title = reader.readRow(1);
            String titleName = "[序号, 省份, 市, 区/县级, *结构类型, *结构类型, *设防情况, 年代, 用途, 用途, 层数, 烈度, 基本完好, 轻微破坏sl, 中等破坏ml, 严重破坏el, 倒塌c]";
            if (!titleName.equals(title.toString())) {
                return RestResponse.fail("导入失败，请检查表头是否改动");
            }
            List<List<Object>> read = reader.read(2, reader.getRowCount());
            if (read.size() == 0) {
                return RestResponse.fail("导入失败，表格中无数据");
            }
            //数据校验
            RestResponse rs = bvParameterVerification(read.size(), read);
            if (rs.getCode() != 200) {
                return RestResponse.fail(rs.getMessage());
            }
            ArrayList<CbvInfoEntity> dataList = new ArrayList<>();
            for (List<Object> objects : read) {
                CbvInfoEntity cbvInfoEntity = new CbvInfoEntity();
                cbvInfoEntity.setCbviId(UUIDGenerator.getUUID());
                cbvInfoEntity.setProvince(objects.get(1).toString());
                cbvInfoEntity.setCity(objects.get(2).toString());
                cbvInfoEntity.setCounty(objects.get(3).toString());
                cbvInfoEntity.setStructureType(objects.get(4).toString());
                cbvInfoEntity.setStructureType1(objects.get(5).toString());
                cbvInfoEntity.setFortification(objects.get(6).toString());
                cbvInfoEntity.setYears(objects.get(7).toString());
                cbvInfoEntity.setUse0(objects.get(8).toString());
                cbvInfoEntity.setUse1(objects.get(9).toString());
                cbvInfoEntity.setCs(objects.get(10).toString());
                cbvInfoEntity.setIntensity(objects.get(11).toString());
                cbvInfoEntity.setBasicallyIntact(new BigDecimal(objects.get(12).toString()));
                cbvInfoEntity.setMinorDamage(new BigDecimal(objects.get(13).toString()));
                cbvInfoEntity.setModerateDamage(new BigDecimal(objects.get(14).toString()));
                cbvInfoEntity.setSeriousDamage(new BigDecimal(objects.get(15).toString()));
                cbvInfoEntity.setCollapse(new BigDecimal(objects.get(16).toString()));
                cbvInfoEntity.setCreateUser(PlatformSessionContext.getUserID());
                cbvInfoEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                cbvInfoEntity.setUserName(sUser.getUserName());
                cbvInfoEntity.setDelFlag(YNEnum.N.toString());
                cbvInfoEntity.setDataType(FxfzConstants.CZT_JZWYSX_INFO);
                cbvInfoEntity.setCurveOrMatrix(1);
                cbvInfoEntity.setBasicLibrary("0");
                //此字段作为筛选数据使用
                cbvInfoEntity.setOrderField(cbvInfoEntity.getProvince() + "_" + cbvInfoEntity.getCity() + "_" + cbvInfoEntity.getCounty()
                        + "_" + cbvInfoEntity.getUse0() + "_" + cbvInfoEntity.getUse1() + "_" + cbvInfoEntity.getStructureType() + "_" + cbvInfoEntity.getStructureType1()
                        + "_" + cbvInfoEntity.getYears() + "_" + cbvInfoEntity.getCs() + "_" + cbvInfoEntity.getFortification());
                dataList.add(cbvInfoEntity);
            }
            Map<String, List<CbvInfoEntity>> collect = dataList.stream().collect(Collectors.groupingBy(CbvInfoEntity::getOrderField));
            collect.forEach((k, v) -> {
                String generationNumber = this.getNumber(RedisKeyConstants.CZT_JZWYSX_KEY);
                String[] split = k.split("_");
                String number = "QYDR" + "-" + GenerationNumberUtil.getCityInitials(split[0]) + "-" +
                        GenerationNumberUtil.type(split[5], split[6]) + "-" +
                        GenerationNumberUtil.getFs(split[9]) + "-" + generationNumber;
                for (CbvInfoEntity cbvInfoEntity : v) {
                    CbvInfoMatrixValueEntity cbvInfoMatrixValueEntity = new CbvInfoMatrixValueEntity();
                    cbvInfoMatrixValueEntity.setCbviValueId(UUIDGenerator.getUUID());
                    cbvInfoMatrixValueEntity.setCbviId(v.get(0).getCbviId());
                    cbvInfoMatrixValueEntity.setIntensity(cbvInfoEntity.getIntensity());
                    cbvInfoMatrixValueEntity.setBasicallyIntact(cbvInfoEntity.getBasicallyIntact());
                    cbvInfoMatrixValueEntity.setMinorDamage(cbvInfoEntity.getMinorDamage());
                    cbvInfoMatrixValueEntity.setModerateDamage(cbvInfoEntity.getModerateDamage());
                    cbvInfoMatrixValueEntity.setSeriousDamage(cbvInfoEntity.getSeriousDamage());
                    cbvInfoMatrixValueEntity.setCollapse(cbvInfoEntity.getCollapse());
                    cbvInfoMatrixValueEntity.setCreateUser(PlatformSessionContext.getUserID());
                    cbvInfoMatrixValueEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                    cbvInfoMatrixValueEntity.setDelFlag(YNEnum.N.toString());
                    cbvInfoEntity.setNumber(number);
                    bacInformationRepository.saveBvInformationValue(cbvInfoMatrixValueEntity);
                }
                bacInformationRepository.saveBvInformation(v.get(0));
            });
            return RestResponse.succeed("导入成功!");
        } catch (Exception e) {
            String message = "导入失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }


    @Override
    public RestResponse uploadSingleBvInformation(MultipartFile file) {
        try {
            ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
            List<Object> title = reader.readRow(0);
            String titleName = "[         破坏程度\n" +
                    "烈度, 基本完好, 轻微破坏sl, 中等破坏ml, 严重破坏el, 倒塌c, ]";
            if (!titleName.equals(title.toString())) {
                return RestResponse.fail("导入失败，请检查表头是否改动");
            }
            List<List<Object>> read = reader.read(1, reader.getRowCount());
            if (read.size() == 0) {
                return RestResponse.fail("导入失败，表格中无数据");
            }
            //数据校验
            RestResponse rs = bvValueParameterVerification(read.size(), read);
            if (rs.getCode() != 200) {
                return RestResponse.fail(rs.getMessage());
            }
            ArrayList<CbvInfoMatrixValueEntity> data = new ArrayList<>();
            for (List<Object> objects : read) {
                CbvInfoMatrixValueEntity cbvInfoMatrixValueEntity = new CbvInfoMatrixValueEntity();
                cbvInfoMatrixValueEntity.setIntensity(objects.get(0).toString());
                cbvInfoMatrixValueEntity.setBasicallyIntact(new BigDecimal(objects.get(1).toString()));
                cbvInfoMatrixValueEntity.setMinorDamage(new BigDecimal(objects.get(2).toString()));
                cbvInfoMatrixValueEntity.setModerateDamage(new BigDecimal(objects.get(3).toString()));
                cbvInfoMatrixValueEntity.setSeriousDamage(new BigDecimal(objects.get(4).toString()));
                cbvInfoMatrixValueEntity.setCollapse(new BigDecimal(objects.get(5).toString()));
                data.add(cbvInfoMatrixValueEntity);
            }
            return RestResponse.succeed(data);
        } catch (Exception e) {
            String message = "导入失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    private RestResponse bvValueParameterVerification(int size, List<List<Object>> data) {
        for (int i = 0; i < size; i++) {
            List<Object> objects = data.get(i);
            BigDecimal value = new BigDecimal(objects.get(1).toString()).add(new BigDecimal(objects.get(2).toString()))
                    .add(new BigDecimal(objects.get(3).toString())).add(new BigDecimal(objects.get(4).toString()))
                    .add(new BigDecimal(objects.get(5).toString())).setScale(1, RoundingMode.HALF_UP);
            if (!predict(value)) {
                return RestResponse.fail("第" + (i + 1) + "行总和应为100");
            }
            if (StringUtils.isBlank(objects.get(0).toString()))
                return RestResponse.fail("第" + (i + 1) + "行的{烈度}不能为空！");
            if (StringUtils.isBlank(objects.get(1).toString()))
                return RestResponse.fail("第" + (i + 1) + "行的{基本完好}不能为空！");
            if (StringUtils.isBlank(objects.get(2).toString()))
                return RestResponse.fail("第" + (i + 1) + "行的{轻微破坏sl}不能为空！");
            if (StringUtils.isBlank(objects.get(3).toString()))
                return RestResponse.fail("第" + (i + 1) + "行的{中等破坏ml}不能为空！");
            if (StringUtils.isBlank(objects.get(4).toString()))
                return RestResponse.fail("第" + (i + 1) + "行的{严重破坏el}不能为空！");
            if (StringUtils.isBlank(objects.get(5).toString()))
                return RestResponse.fail("第" + (i + 1) + "行的{倒塌c}不能为空！");
        }
        return RestResponse.succeed();
    }


    private RestResponse bvParameterVerification(int size, List<List<Object>> data) {
        for (int i = 0; i < size; i++) {
            List<Object> objects = data.get(i);
            BigDecimal value = new BigDecimal(objects.get(12).toString()).add(new BigDecimal(objects.get(13).toString()))
                    .add(new BigDecimal(objects.get(14).toString())).add(new BigDecimal(objects.get(15).toString()))
                    .add(new BigDecimal(objects.get(16).toString())).setScale(1, RoundingMode.HALF_UP);
            if (!predict(value)) {
                return RestResponse.fail("第" + (i + 3) + "行总和应为1");
            }
            if (StringUtils.isBlank(objects.get(1).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{省份}不能为空！");
            if (StringUtils.isBlank(objects.get(2).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{市}不能为空！");
            if (StringUtils.isBlank(objects.get(3).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{区县}不能为空！");
            if (StringUtils.isBlank(objects.get(4).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{结构类型}不能为空！");
            if (StringUtils.isBlank(objects.get(6).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{设防情况}不能为空！");
            if (StringUtils.isBlank(objects.get(7).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{年代}不能为空！");
            if (StringUtils.isBlank(objects.get(8).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{用途}不能为空！");
            if (StringUtils.isBlank(objects.get(9).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{用途}不能为空！");
            if (StringUtils.isBlank(objects.get(10).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{层数}不能为空！");
            if (StringUtils.isBlank(objects.get(11).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{烈度}不能为空！");
            if (StringUtils.isBlank(objects.get(12).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{基本完好}不能为空！");
            if (StringUtils.isBlank(objects.get(13).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{轻微破坏sl}不能为空！");
            if (StringUtils.isBlank(objects.get(14).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{中等破坏ml}不能为空！");
            if (StringUtils.isBlank(objects.get(15).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{严重破坏el}不能为空！");
            if (StringUtils.isBlank(objects.get(16).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{倒塌c}不能为空！");
        }
        return RestResponse.succeed();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public RestResponse uploadPobStructure(MultipartFile file) {
        try {
            String userID = PlatformSessionContext.getUserID();
            // userID="80cd530287e54c6788925adf2dfc9da1";
            String user = sUserService.getSUser(userID);
            SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
            ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
            List<List<Object>> read = reader.read(3, reader.getRowCount());
            List<Object> title = reader.readRow(1);
            System.out.println(title.toString());
            String titleName = "[序号, *建筑编号, *楼层序号, *用途, *用途, 省份, 市, 区/县级, *设防情况, *建造年代, *楼层对应的砂浆强度(M), *外墙厚度, *内墙厚度," +
                    " *层宽, *层长, *总楼层数, *墙体截面积, *（楼层）建筑面积, 结构无明显质量问题, 平立面规则, 建筑抗震设计规范, 楼屋盖类型, 承重墙间距]";
            if (!titleName.equals(title.toString())) {
                return RestResponse.fail("导入失败，请检查表头是否改动");
            }
            if (read.size() < 1) {
                return RestResponse.fail("导入失败，表格中无数据");
            }
            //数据校验
            RestResponse rs = pobParameterVerification(read.size(), read);
            if (rs.getCode() != 200) {
                return RestResponse.fail(rs.getMessage());
            }
            /**
             * key:建筑编号
             * values:
             *      jsonObject:
             *          cbcbInfoEntity 建筑信息（楼）
             *          detailList  楼的详情（楼层）
             */
            Map<String, JSONObject> map = new HashMap<>();
            JSONObject jsonObject = null;
            List<CbcbDetailEntity> detailList = null;
            for (List<Object> objects : read) {
                String buildingNumber = objects.get(1).toString();//建筑编号,同一栋楼编号相同，不同的楼编号不同
                CbcbInfoEntity cbcbInfoEntity = null;
                //同一栋楼的信息放到一起
                if (map.containsKey(buildingNumber)) {
                    jsonObject = map.get(buildingNumber);
                    cbcbInfoEntity = JSON.parseObject(JSON.toJSONString(jsonObject.getJSONObject("cbcbInfoEntity")),
                            CbcbInfoEntity.class);
                    detailList = JSON.parseArray(JSON.toJSONString(jsonObject.getJSONArray("detailList")), CbcbDetailEntity.class);
                } else {
                    jsonObject = new JSONObject();
                    cbcbInfoEntity = new CbcbInfoEntity();
                    cbcbInfoEntity.setCbcbiId(UUIDGenerator.getUUID());
                    cbcbInfoEntity.setBuildingNumber(objects.get(1).toString());
                    cbcbInfoEntity.setPurpose(objects.get(3).toString());
                    cbcbInfoEntity.setPurpose1(objects.get(4).toString());
                    cbcbInfoEntity.setProvince(objects.get(5).toString());
                    cbcbInfoEntity.setCity(objects.get(6).toString());
                    cbcbInfoEntity.setCounty(objects.get(7).toString());
                    cbcbInfoEntity.setStructureType("砌体结构");
                    cbcbInfoEntity.setStructureType1("砖混结构");
                    cbcbInfoEntity.setFortification(objects.get(8).toString());
                    cbcbInfoEntity.setYears(objects.get(9).toString());
                    cbcbInfoEntity.setOutThickness(Double.parseDouble(objects.get(11).toString()));
                    cbcbInfoEntity.setInnerThickness(Double.parseDouble(objects.get(12).toString()));
                    cbcbInfoEntity.setTotalFloor(Integer.parseInt(objects.get(15).toString()));
                    if (cbcbInfoEntity.getTotalFloor().compareTo(3) < 1) {
                        cbcbInfoEntity.setFloor("1-3层");
                    } else {
                        cbcbInfoEntity.setFloor("4-8层");
                    }
                    cbcbInfoEntity.setCiType1("结构无明显质量问题");
                    if ("是".equals(objects.get(18).toString())) {
                        cbcbInfoEntity.setCiType1Value(1);
                    } else {
                        cbcbInfoEntity.setCiType1Value(2);
                    }
                    cbcbInfoEntity.setCiType2("平立面规则");
                    if ("规则".equals(objects.get(19).toString())) {
                        cbcbInfoEntity.setCiType2Value(1);
                    } else {
                        cbcbInfoEntity.setCiType2Value(2);
                    }
                    cbcbInfoEntity.setCiType3("建筑抗震设计规范");
                    cbcbInfoEntity.setCiType3Value(BuildingSeismicResistanceEnum.getByName(objects.get(20).toString()));
                    cbcbInfoEntity.setCiType4("楼屋盖类型");
                    cbcbInfoEntity.setCiType4Value(BuildingRoofEnum.getByName1(objects.get(21).toString()));
                    cbcbInfoEntity.setSpacing(Double.valueOf(objects.get(22).toString()));
                    cbcbInfoEntity.setCreateUser(userID);
                    cbcbInfoEntity.setUserName(sUser.getUserName());
                    cbcbInfoEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                    cbcbInfoEntity.setDelFlag(YNEnum.N.toString());
                    cbcbInfoEntity.setCalculateOrNot("0");
                    cbcbInfoEntity.setDataType(FxfzConstants.CZT_ZHJG_INFO);
                    cbcbInfoEntity.setBasicLibrary("0");
                    String number = generationNumberUtil.getCityInitials(cbcbInfoEntity.getProvince()) + "-" +
                            generationNumberUtil.type(cbcbInfoEntity.getStructureType(), cbcbInfoEntity.getStructureType1()) + "-" +
                            generationNumberUtil.getFs(cbcbInfoEntity.getFortification()) + "-" + this.getNumber(RedisKeyConstants.CZT_ZHJG_KEY);
                    cbcbInfoEntity.setNumber(number);
                    jsonObject.put("cbcbInfoEntity", cbcbInfoEntity);
                    detailList = new ArrayList<>();
                }
                CbcbDetailEntity cbcbDetailEntity = new CbcbDetailEntity();
                cbcbDetailEntity.setCbcbdId(UUIDGenerator.getUUID());
                cbcbDetailEntity.setFloorNumber(Integer.valueOf(objects.get(2).toString()));
                cbcbDetailEntity.setMortar(Double.parseDouble(objects.get(10).toString()));
                cbcbDetailEntity.setWidth(Double.parseDouble(objects.get(13).toString()));
                cbcbDetailEntity.setLength(Double.parseDouble(objects.get(14).toString()));
                cbcbDetailEntity.setSectionArea(new BigDecimal(objects.get(16).toString()));
                cbcbDetailEntity.setBuildArea(new BigDecimal(objects.get(17).toString()));
                cbcbDetailEntity.setCbcbiId(cbcbInfoEntity.getCbcbiId());
                cbcbDetailEntity.setCreateUser(userID);
                cbcbDetailEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                cbcbDetailEntity.setDelFlag(YNEnum.N.toString());
                detailList.add(cbcbDetailEntity);
                jsonObject.put("detailList", detailList);
                map.put(buildingNumber, jsonObject);
            }
            countPobStructure(map, "", "");
            return RestResponse.succeed("导入成功!");
        } catch (IOException e) {
            String message = "导入失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    public RestResponse uploadPobStructure1(MultipartFile file) {
        try {
            String user = sUserService.getSUser(PlatformSessionContext.getUserID());
            SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
            ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
            List<List<Object>> read = reader.read(2, reader.getRowCount());
            List<Object> title = reader.readRow(1);
            String titleName = "[序号, 用途, 用途, 省份, 市, 区/县级, 结构类型, 结构类型, 设防情况, 年代, 楼层号, 楼层对应的砂浆标号(Rm), 外墙厚度(m), 内墙厚度(m), 层宽(m), 层长(m), 总楼层数, 墙体截面积, 建筑面积, 墙的间距符合现行抗震设计规范要求, 刚性楼屋盖, 结构无明显质量问题, 平立面规则, 建筑抗震设计规范, 建筑抗震设计规范]";
            if (!titleName.equals(title.toString())) {
                return RestResponse.fail("导入失败，请检查表头是否改动");
            }
            if (read.size() == 0) {
                return RestResponse.fail("导入失败，表格中无数据");
            }
            //数据校验
            RestResponse rs = pobParameterVerification1(read.size(), read);
            if (rs.getCode() != 200) {
                return RestResponse.fail(rs.getMessage());
            }
            ArrayList<CbcpInfoEntity> dataList = new ArrayList<>();
            for (List<Object> objects : read) {
                CbcpInfoEntity cbcpInfoEntity = new CbcpInfoEntity();
                cbcpInfoEntity.setCbcpiId(UUIDGenerator.getUUID());
                cbcpInfoEntity.setPurpose(objects.get(1).toString());
                cbcpInfoEntity.setPurpose1(objects.get(2).toString());
                cbcpInfoEntity.setProvince(objects.get(3).toString());
                cbcpInfoEntity.setCity(objects.get(4).toString());
                cbcpInfoEntity.setCounty(objects.get(5).toString());
                cbcpInfoEntity.setStructureType(objects.get(6).toString());
                cbcpInfoEntity.setStructureType1(objects.get(7).toString());
                cbcpInfoEntity.setFortification(objects.get(8).toString());
                cbcpInfoEntity.setYears(objects.get(9).toString());
                cbcpInfoEntity.setFloor(objects.get(10).toString());
                cbcpInfoEntity.setMortar(Double.parseDouble(objects.get(11).toString()));
                cbcpInfoEntity.setOutThickness(Double.parseDouble(objects.get(12).toString()));
                cbcpInfoEntity.setInnerThickness(Double.parseDouble(objects.get(13).toString()));
                cbcpInfoEntity.setWidth(Double.parseDouble(objects.get(14).toString()));
                cbcpInfoEntity.setLength(Double.parseDouble(objects.get(15).toString()));
                cbcpInfoEntity.setTotalFloor(Integer.parseInt(objects.get(16).toString()));
                cbcpInfoEntity.setSectionArea(new BigDecimal(objects.get(17).toString()));
                cbcpInfoEntity.setBuildArea(new BigDecimal(objects.get(18).toString()));
                ArrayList<String> ciList = new ArrayList<>();
                ciList.add(objects.get(19).toString());
                ciList.add(objects.get(20).toString());
                ciList.add(objects.get(21).toString());
                ciList.add(objects.get(22).toString());
                ciList.add(objects.get(24).toString());
                ArrayList ci = getCiValue(ciList, objects.get(23).toString());
                cbcpInfoEntity.setCorrectionCoefficient(ci.get(0).toString());
                cbcpInfoEntity.setCi(new BigDecimal(ci.get(1).toString()));

                cbcpInfoEntity.setCreateUser(PlatformSessionContext.getUserID());
                cbcpInfoEntity.setUserName(sUser.getUserName());
                cbcpInfoEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                cbcpInfoEntity.setDelFlag(YNEnum.N.toString());
                cbcpInfoEntity.setCalculateOrNot("0");
                cbcpInfoEntity.setDataType(FxfzConstants.CZT_ZHJG_INFO);
                cbcpInfoEntity.setBasicLibrary("0");
                String number = generationNumberUtil.getCityInitials(cbcpInfoEntity.getProvince()) + "-" +
                        generationNumberUtil.type(cbcpInfoEntity.getStructureType(), cbcpInfoEntity.getStructureType1()) + "-" +
                        generationNumberUtil.getFs(cbcpInfoEntity.getFortification()) + "-" + this.getNumber(RedisKeyConstants.CZT_ZHJG_KEY);
                cbcpInfoEntity.setNumber(number);
                dataList.add(cbcpInfoEntity);
            }
            countPobStructure1(dataList);
            return RestResponse.succeed("导入成功!");
        } catch (IOException e) {
            String message = "导入失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    private ArrayList getRcpCiValue(ArrayList<String> ciList, String conditionName) {
        ArrayList<Object> resultList = new ArrayList<>();
        String[] conditions = {"现浇钢筋混凝土构件沿高度断面无突变", "平面对称", "施工质量良好", conditionName};
        BigDecimal ci = BigDecimal.ZERO;
        StringBuilder ciIds = new StringBuilder();
        for (int i = 0; i < ciList.size(); i++) {
            CStructureCiEntity entity = zqtCiRepository.getCsByCondition(ciList.get(i), conditions[i]);
            ci = ci.add(BigDecimal.valueOf(entity.getConditionValue()));
            if (i == ciList.size()) {
                ciIds.append(entity.getCcsrId());
            } else {
                ciIds.append(entity.getCcsrId() + ",");
            }
        }
        resultList.add(ciIds);
        resultList.add(ci);
        return resultList;
    }

    private ArrayList getCiValue(ArrayList<String> ciList, String conditionName) {
        ArrayList<Object> resultList = new ArrayList<>();
        //结构无明显质量问题, 平立面规则, 建筑抗震设计规范, 楼屋盖类型, 承重墙间距
        String[] conditions = {"结构无明显质量问题", "平立面规则", "楼屋盖类型", "承重墙间距", conditionName};
        BigDecimal ci = BigDecimal.ZERO;
        StringBuilder ciIds = new StringBuilder();
        for (int i = 0; i < ciList.size(); i++) {
            ZqtEntity entity = zqtCiRepository.getZqtByCondition(ciList.get(i), conditions[i]);
            ci = ci.add(BigDecimal.valueOf(entity.getCiValue()));
            if (i == ciList.size()) {
                ciIds.append(entity.getCbrmId());
            } else {
                ciIds.append(entity.getCbrmId() + ",");
            }
        }
        resultList.add(ciIds);
        resultList.add(ci);
        return resultList;
    }

    /**
     * key:建筑编号
     * values:
     * jsonObject:
     * cbcbInfoEntity 建筑信息（楼）
     * detailList  楼的详情（楼层）
     * id  枢纽建筑主表id 枢纽建筑调接口时候传参，其他调用传空，
     */
    public List<String> countPobStructure(Map<String, JSONObject> map, String id, String versionId) {
        //破坏状态list
        ArrayList<String> list = new ArrayList<>();
        for (Map.Entry<String, JSONObject> entry : map.entrySet()) {
            JSONObject value = entry.getValue();
            CbcbInfoEntity cbcbInfoEntity = JSON.parseObject(JSON.toJSONString(value.getJSONObject("cbcbInfoEntity")),
                    CbcbInfoEntity.class);
            cbcbInfoEntity.setCalculateOrNot("1");
            if (!StrUtil.isBlankIfStr(id)) {
                cbcbInfoEntity.setTableId(id);
            }
            if (!StrUtil.isBlankIfStr(versionId)) {
                cbcbInfoEntity.setVersionId(versionId);
            }

            Integer n = cbcbInfoEntity.getTotalFloor();//总楼层数
            //根据条件查询具体的值
            String name1 = null;
            if (1 == cbcbInfoEntity.getCiType1Value()) {
                name1 = "不满足";
            } else {
                name1 = "满足";
            }
            ZqtEntity type1 = zqtCiRepository.getZqtByConditionAndValue(cbcbInfoEntity.getCiType1(), name1);
            //平立面规则，规则：满足；不规则：不满足
            String name2 = null;
            if (1 == cbcbInfoEntity.getCiType2Value()) {
                name2 = "满足";
            } else {
                name2 = "不满足";
            }
            ZqtEntity type2 = zqtCiRepository.getZqtByConditionAndValue(cbcbInfoEntity.getCiType2(), name2);
            ZqtEntity type3 = zqtCiRepository.getZqtByConditionAndValue(BuildingSeismicResistanceEnum.getByCode(cbcbInfoEntity.getCiType3Value()), "满足");
            Double type4 = BuildingRoofEnum.getByCode(cbcbInfoEntity.getCiType4Value(), cbcbInfoEntity.getSpacing(), BuildingRoofEnum.getByName(cbcbInfoEntity.getFortification()));
            BigDecimal ci = BigDecimal.valueOf(type1.getCiValue() + type2.getCiValue() + type3.getCiValue() + type4);
            cbcbInfoEntity.setCi(ci);
            cbcbInfoEntity.setCorrectionCoefficient(type1.getCbrmId() + "," + type2.getCbrmId() + "," + type3.getCbrmId());
            bacInformationRepository.savePobStructure1(cbcbInfoEntity);
            BigDecimal As = BigDecimal.ZERO;
            BigDecimal rs = BigDecimal.ZERO;
            BigDecimal Rs = BigDecimal.ZERO;
            BigDecimal Ds = BigDecimal.ZERO;
            BigDecimal Dsm = BigDecimal.ZERO;
            Map<Integer, JSONObject> jsonMap1 = new HashMap<>();
            Map<Integer, JSONObject> jsonMap2 = new HashMap<>();
            Map<Integer, Map<String, Integer>> mapMap = new HashMap<>();
            List<CbcbDetailEntity> detailList = JSON.parseArray(JSON.toJSONString(value.getJSONArray("detailList")),
                    CbcbDetailEntity.class);
            for (CbcbDetailEntity cbcbDetailEntity : detailList) {
                bacInformationRepository.savePobStructure2(cbcbDetailEntity);
                double Rm = cbcbDetailEntity.getMortar() * 10;//楼层对应的砂浆标号
                BigDecimal Fs = cbcbDetailEntity.getSectionArea().divide(BigDecimal.valueOf(10000), 2, BigDecimal.ROUND_UP);//墙体截面积
                BigDecimal as = cbcbDetailEntity.getBuildArea().divide(BigDecimal.valueOf(10000), 2, BigDecimal.ROUND_UP);//建筑面积
//                BigDecimal Fs = cbcbDetailEntity.getSectionArea();//墙体截面积
//                BigDecimal as = cbcbDetailEntity.getBuildArea();//建筑面积
                int i = cbcbDetailEntity.getFloorNumber();//楼层序号
//                rs = BigDecimal.valueOf(0.14).multiply(BigDecimal.valueOf(n - i + 1)).add(BigDecimal.valueOf(0.014 * Rm)).add(BigDecimal.valueOf(0.5));
//                As = BigDecimal.valueOf(2 * n + 1).divide(BigDecimal.valueOf(3 * ((n + i) * (n - i + 1)) / 2), 2,
//                        BigDecimal.ROUND_HALF_UP);
//                Rs = As.multiply(Fs.divide(BigDecimal.valueOf(2).multiply(as), 4, BigDecimal.ROUND_HALF_UP)).multiply(rs).setScale(2, RoundingMode.HALF_UP);
                rs = BigDecimal.valueOf(0.14).multiply(BigDecimal.valueOf(n - i + 1)).add(BigDecimal.valueOf(0.014 * Rm)).add(BigDecimal.valueOf(0.5)).setScale(2,RoundingMode.HALF_UP);
                As = BigDecimal.valueOf(2 * n + 1).divide(BigDecimal.valueOf(3 * ((n + i) * (n - i + 1)) / 2), 2,
                        BigDecimal.ROUND_HALF_UP);
                Rs = As.multiply(Fs.divide(BigDecimal.valueOf(2).multiply(as), 5, BigDecimal.ROUND_HALF_UP)).multiply(rs).setScale(2, RoundingMode.HALF_UP);

                CztBrickConcreteDestroyCalc entity1 = new CztBrickConcreteDestroyCalc();
                entity1.setProjectId(cbcbInfoEntity.getCbcbiId());
                entity1.setCs(i);
                entity1.setQtkjcd(rs);
                entity1.setDzjlzsxs(As);
                entity1.setResistanceForce(Rs);

                for (int j = 6; j < 11; j++) {
                    switch (j) {
                        case 6:
                            Ds = BigDecimal.valueOf(2.032).subtract(BigDecimal.valueOf(0.007).multiply(Rs)).setScale(2, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD6(Ds);
                            break;
                        case 7:
                            Ds = BigDecimal.valueOf(1.977).subtract(BigDecimal.valueOf(0.006).multiply(Rs)).setScale(2, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD7(Ds);
                            break;
                        case 8:
                            Ds = BigDecimal.valueOf(1.975).subtract(BigDecimal.valueOf(0.005).multiply(Rs)).setScale(2, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD8(Ds);
                            break;
                        case 9:
                            Ds = BigDecimal.valueOf(1.866).subtract(BigDecimal.valueOf(0.004).multiply(Rs)).setScale(2, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD9(Ds);
                            break;
                        case 10:
                            Ds = BigDecimal.valueOf(1.74).subtract(BigDecimal.valueOf(0.003).multiply(Rs)).setScale(2, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD10(Ds);
                            break;
                    }
                    Dsm = Ds.multiply(BigDecimal.valueOf(1).add(ci)).setScale(2,
                            RoundingMode.HALF_UP);
                    switch (j) {
                        case 6:
                            entity1.setDegree6(Dsm);
                            break;
                        case 7:
                            entity1.setDegree7(Dsm);
                            break;
                        case 8:
                            entity1.setDegree8(Dsm);
                            break;
                        case 9:
                            entity1.setDegree9(Dsm);
                            break;
                        case 10:
                            entity1.setDegree10(Dsm);
                            break;
                    }
                    JSONObject jsonObject1 = null;
                    if (jsonMap1.containsKey(j)) {
                        jsonObject1 = jsonMap1.get(j);
                    } else {
                        jsonObject1 = new JSONObject();
                    }
                    jsonObject1.put("f" + i, Dsm);
                    jsonMap1.put(j, jsonObject1);
                    String DsmL = null;
                    if (Dsm.compareTo(BigDecimal.valueOf(0.1)) < 1) {
                        DsmL = "基本完好";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.1)) > 0 && Dsm.compareTo(BigDecimal.valueOf(0.3)) < 1) {
                        DsmL = "轻微破坏";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.3)) > 0 && Dsm.compareTo(BigDecimal.valueOf(0.55)) < 1) {
                        DsmL = "中等破坏";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.55)) > 0 && Dsm.compareTo(BigDecimal.valueOf(0.85)) < 1) {
                        DsmL = "严重破坏";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.85)) > 0) {
                        DsmL = "毁坏";
                    }
                    JSONObject jsonObject2 = null;
                    if (jsonMap2.containsKey(j)) {
                        jsonObject2 = jsonMap2.get(j);
                    } else {
                        jsonObject2 = new JSONObject();
                    }
                    jsonObject2.put("floor" + i, DsmL);
                    jsonMap2.put(j, jsonObject2);

                    Map<String, Integer> map1 = null;
                    if (mapMap.containsKey(j)) {
                        map1 = mapMap.get(j);
                    } else {
                        map1 = new HashMap<>();
                    }
                    Integer integer = 0;
                    if (map1.containsKey(DsmL)) {
                        integer = map1.get(DsmL);
                        integer++;
                    } else {
                        integer = 1;
                    }
                    map1.put(DsmL, integer);
                    mapMap.put(j, map1);
                }
                pobStructureService.saveBrickConcreteDestroyCalc(entity1);
            }
            for (int k = 6; k < 11; k++) {
                CztBrickConcreteDestroyResult entity = new CztBrickConcreteDestroyResult();
                entity.setProjectId(cbcbInfoEntity.getCbcbiId());
                entity.setBreakState(k + "度");
                entity.setJsonData1(jsonMap1.get(k).toJSONString());
                entity.setJsonData2(jsonMap2.get(k).toJSONString());
                entity.setConclusion(PobStructureServiceImpl.getConclusion(mapMap, k));
                list.add(PobStructureServiceImpl.getConclusion(mapMap, k));
                pobStructureService.saveCztBrickConcreteDestroyResult(entity);
            }
        }
        return list;
    }

    public void countPobStructure1(List<CbcpInfoEntity> it) {
        for (CbcpInfoEntity cbcpInfoEntity : it) {
            cbcpInfoEntity.setCalculateOrNot("1");
            bacInformationRepository.savePobStructure(cbcpInfoEntity);
            Integer n = cbcpInfoEntity.getTotalFloor();//总楼层数
            double Rm = cbcpInfoEntity.getMortar() * 10;//楼层对应的砂浆标号
            BigDecimal Fs = cbcpInfoEntity.getSectionArea();//墙体截面积
            BigDecimal as = cbcpInfoEntity.getBuildArea();//建筑面积
            BigDecimal As = BigDecimal.ZERO;
            BigDecimal rs = BigDecimal.ZERO;
            BigDecimal Rs = BigDecimal.ZERO;
            BigDecimal Ds = BigDecimal.ZERO;
            BigDecimal Dsm = BigDecimal.ZERO;
            Map<Integer, JSONObject> jsonMap1 = new HashMap<>();
            Map<Integer, JSONObject> jsonMap2 = new HashMap<>();
            Map<Integer, Map<String, Integer>> mapMap = new HashMap<>();
            for (int i = 1; i <= n; i++) {
                rs = BigDecimal.valueOf(0.14).multiply(BigDecimal.valueOf(n - i + 1)).add(BigDecimal.valueOf(0.014 * Rm)).add(BigDecimal.valueOf(0.5));
                int sum = i, s = i + 1;
                while (s <= n) {
                    sum = sum + s;
                    s = s + 1;
                }
                As = BigDecimal.valueOf(2 * n + 1).divide(BigDecimal.valueOf(3 * sum), 2, BigDecimal.ROUND_HALF_UP);
                Rs = As.multiply(Fs.divide(BigDecimal.valueOf(2).multiply(as), 4, BigDecimal.ROUND_HALF_UP)).multiply(rs).setScale(2, RoundingMode.HALF_UP);

                CztBrickConcreteDestroyCalc entity1 = new CztBrickConcreteDestroyCalc();
                entity1.setProjectId(cbcpInfoEntity.getCbcpiId());
                entity1.setCs(i);
                entity1.setQtkjcd(rs);
                entity1.setDzjlzsxs(As);
                entity1.setResistanceForce(Rs);

                for (int j = 6; j < 11; j++) {
                    switch (j) {
                        case 6:
                            Ds = BigDecimal.valueOf(2.032).subtract(BigDecimal.valueOf(0.007).multiply(Rs)).setScale(3, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD6(Ds);
                            break;
                        case 7:
                            Ds = BigDecimal.valueOf(1.977).subtract(BigDecimal.valueOf(0.006).multiply(Rs)).setScale(3, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD7(Ds);
                            break;
                        case 8:
                            Ds = BigDecimal.valueOf(1.975).subtract(BigDecimal.valueOf(0.005).multiply(Rs)).setScale(3, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD8(Ds);
                            break;
                        case 9:
                            Ds = BigDecimal.valueOf(1.866).subtract(BigDecimal.valueOf(0.004).multiply(Rs)).setScale(3, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD9(Ds);
                            break;
                        case 10:
                            Ds = BigDecimal.valueOf(1.74).subtract(BigDecimal.valueOf(0.003).multiply(Rs)).setScale(3, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD10(Ds);
                            break;
                    }
                    BigDecimal ci = cbcpInfoEntity.getCi();
                    Dsm = Ds.multiply(BigDecimal.valueOf(1).add(ci)).setScale(2,
                            RoundingMode.HALF_UP);
                    switch (j) {
                        case 6:
                            entity1.setDegree6(Dsm);
                            break;
                        case 7:
                            entity1.setDegree7(Dsm);
                            break;
                        case 8:
                            entity1.setDegree8(Dsm);
                            break;
                        case 9:
                            entity1.setDegree9(Dsm);
                            break;
                        case 10:
                            entity1.setDegree10(Dsm);
                            break;
                    }
                    JSONObject jsonObject1 = null;
                    if (jsonMap1.containsKey(j)) {
                        jsonObject1 = jsonMap1.get(j);
                    } else {
                        jsonObject1 = new JSONObject();
                    }
                    jsonObject1.put("f" + i, Dsm);
                    jsonMap1.put(j, jsonObject1);
                    String DsmL = null;
                    if (Dsm.compareTo(BigDecimal.valueOf(0.1)) < 1) {
                        DsmL = "基本完好";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.1)) > 0 && Dsm.compareTo(BigDecimal.valueOf(0.3)) < 1) {
                        DsmL = "轻微破坏";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.3)) > 0 && Dsm.compareTo(BigDecimal.valueOf(0.55)) < 1) {
                        DsmL = "中等破坏";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.55)) > 0 && Dsm.compareTo(BigDecimal.valueOf(0.85)) < 1) {
                        DsmL = "严重破坏";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.85)) > 0) {
                        DsmL = "毁坏";
                    }
                    JSONObject jsonObject2 = null;
                    if (jsonMap2.containsKey(j)) {
                        jsonObject2 = jsonMap2.get(j);
                    } else {
                        jsonObject2 = new JSONObject();
                    }
                    jsonObject2.put("floor" + i, DsmL);
                    jsonMap2.put(j, jsonObject2);

                    Map<String, Integer> map = null;
                    if (mapMap.containsKey(j)) {
                        map = mapMap.get(j);
                    } else {
                        map = new HashMap<>();
                    }
                    Integer integer = 0;
                    if (map.containsKey(DsmL)) {
                        integer = map.get(DsmL);
                        integer++;
                    } else {
                        integer = 1;
                    }
                    map.put(DsmL, integer);
                    mapMap.put(j, map);
                }
                pobStructureService.saveBrickConcreteDestroyCalc(entity1);
            }
            for (int k = 6; k < 11; k++) {
                CztBrickConcreteDestroyResult entity = new CztBrickConcreteDestroyResult();
                entity.setProjectId(cbcpInfoEntity.getCbcpiId());
                entity.setBreakState(k + "度");
                entity.setJsonData1(jsonMap1.get(k).toJSONString());
                entity.setJsonData2(jsonMap2.get(k).toJSONString());
                Integer num = 0;
                String conclusion = "";
                for (Map.Entry<String, Integer> entry : mapMap.get(k).entrySet()) {
                    if (num.compareTo(entry.getValue()) == 0) {
                        conclusion = conclusion + "," + entry.getKey();
                    } else if (num.compareTo(entry.getValue()) < 0) {
                        conclusion = entry.getKey();
                        num = entry.getValue();
                    }
                }
                if (conclusion.indexOf(",") == 0) {
                    conclusion = conclusion.substring(1);
                }
                entity.setConclusion(conclusion);
                pobStructureService.saveCztBrickConcreteDestroyResult(entity);
            }
        }
    }

    public static RestResponse pobParameterVerification(int size, List<List<Object>> data) {
        //"[序号, 建筑编号, 楼层序号, 用途, 用途, 省份, 市, 区/县级, 设防情况, 建造年代, 楼层对应的砂浆强度(M), 外墙厚度, 内墙厚度," +
        //" 层宽, 层长, 总楼层数, 墙体截面积, （楼层）建筑面积, 结构无明显质量问题, 平立面规则, 建筑抗震设计规范, 楼屋盖类型, 承重墙间距]";
        for (int i = 0; i < size; i++) {
            List<Object> objects = data.get(i);
            if (objects.size() != 23) {
                return RestResponse.fail("第" + (i + 4) + "行的数据存在空值！");
            }
            if (PlatformObjectUtils.isEmpty(objects.get(1) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{建筑编号}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(2) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{楼层序号}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(3) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{用途}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(4) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{用途}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(5) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{省份}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(6) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{市}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(7) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{区/县级}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(8) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{设防情况}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(9) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{建造年代}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(10) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{楼层对应的砂浆强度(M)}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(11) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{外墙厚度}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(12) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{内墙厚度}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(13) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{层宽}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(14) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{层长}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(15) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{总楼层数}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(16) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{墙体截面积}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(17) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{（楼层）建筑面积}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(18) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{结构无明显质量问题}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(19) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{平立面规则}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(20) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{建筑抗震设计规范}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(21) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{楼屋盖类型}不能为空！");
            if (PlatformObjectUtils.isEmpty(objects.get(22) + ""))
                return RestResponse.fail("第" + (i + 4) + "行的{承重墙间距}不能为空！");
        }
        return RestResponse.succeed();
    }

    private RestResponse pobParameterVerification1(int size, List<List<Object>> data) {
        for (int i = 0; i < size; i++) {
            List<Object> objects = data.get(i);
            if (StringUtils.isBlank(objects.get(1).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{用途}不能为空！");
            if (StringUtils.isBlank(objects.get(2).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{用途}不能为空！");
            if (StringUtils.isBlank(objects.get(3).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{省份}不能为空！");
            if (StringUtils.isBlank(objects.get(4).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{市}不能为空！");
            if (StringUtils.isBlank(objects.get(5).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{区县}不能为空！");
            if (StringUtils.isBlank(objects.get(6).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{结构类型}不能为空！");
            if (StringUtils.isBlank(objects.get(7).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{结构类型}不能为空！");
            if (StringUtils.isBlank(objects.get(8).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{设防情况}不能为空！");
            if (StringUtils.isBlank(objects.get(9).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{年代}不能为空！");
            if (StringUtils.isBlank(objects.get(10).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{楼层号}不能为空！");
            if (StringUtils.isBlank(objects.get(11).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{楼层对应的砂浆标号}不能为空！");
            if (StringUtils.isBlank(objects.get(12).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{外墙厚度}不能为空！");
            if (StringUtils.isBlank(objects.get(13).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{内墙厚度}不能为空！");
            if (StringUtils.isBlank(objects.get(14).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{层宽}不能为空！");
            if (StringUtils.isBlank(objects.get(15).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{层长}不能为空！");
            if (StringUtils.isBlank(objects.get(16).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{总楼层数}不能为空！");
            if (StringUtils.isBlank(objects.get(17).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{墙体截面积}不能为空！");
            if (StringUtils.isBlank(objects.get(18).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{建筑面积}不能为空！");
            if (StringUtils.isBlank(objects.get(19).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{墙的间距符合现行抗震设计规范要求}不能为空！");
            if (StringUtils.isBlank(objects.get(20).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{刚性楼屋盖}不能为空！");
            if (StringUtils.isBlank(objects.get(21).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{结构无明显质量问题}不能为空！");
            if (StringUtils.isBlank(objects.get(22).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{平立面规则}不能为空！");
            if (StringUtils.isBlank(objects.get(23).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{建筑抗震设计规范}不能为空！");
            if (StringUtils.isBlank(objects.get(24).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{建筑抗震设计规范}不能为空！");
        }
        return RestResponse.succeed();
    }


    @Autowired
    private SrcAnalyseService srcAnalyseService;

    @Autowired
    private RcpRepository rcpRepository;

    @Autowired
    private CrsEntiretyCiRepository ciRepository;

    @Autowired
    private ExcelReaderPlus excelReaderPlus;

    /**
     * @param file
     * @throws Exception 导入钢混参数
     */
    @Override
    public RestResponse uploadRcpInformationNew(MultipartFile file) throws Exception {
        String user = sUserService.getSUser(PlatformSessionContext.getUserID());
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
        Workbook workBook = null;
        try {
            workBook = PoiExcelUtil.getWorkBook(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        //将解析后的数据放到Map的list中，每个map都是按照numType 分组得到的list.
        List<Map> mapList = new ArrayList<>(4);
        RestResponse restResponse = null;
        Map<String, List<List>> stringListMap = new HashMap<>();
        try {
            for (int numSheet = 0; numSheet < workBook.getNumberOfSheets(); numSheet++) {
                if (numSheet == 0) {
                    //检查表头
                    String title = "建筑物序号,省份,市,区/县级,用途,结构类型,年代,设防情况,层数,场地类别,设计地震分组,阻尼比,现浇钢筋混凝土构件沿高度断面无突变,平面规则,施工质量良好,依据的建筑抗震设计规范,榀数,每榀间距(m),建筑物宽度(mm),每层荷载值(KN/m^2),楼层号,层高,柱编号,钢筋混凝土强度等级,柱净高Hn (m),柱验算方向的截面高h (mm),柱验算方向截面宽b (mm),柱箍筋牌号,柱箍筋截面积Asv  (mm^2),柱箍筋间距s  (mm),柱下端纵向钢筋牌号,柱下端受压区纵向钢筋面积As'  (mm^2),柱下端受拉区纵向钢筋面积As  (mm^2),柱上端纵向钢筋牌号,柱上端受压区纵向钢筋面积As'  (mm^2),柱上端受拉区纵向钢筋面积As  (mm^2),受拉筋合力点到受拉边缘的距离as (mm),受压筋合力点距受压边缘的距离  as‘(mm),备注";
                    //String title = "建筑物序号,省份,市,区/县级,用途,结构类型,年代,设防情况,层数,场地类别,设计地震分组,阻尼比,现浇钢筋混凝土构件沿高度断面无突变,平面规则,施工质量良好,依据的建筑抗震设计规范,榀数,每榀间距(m),建筑物宽度(mm),每层荷载值(KN/m^2),楼层号,层高(m),柱编号,钢筋混凝土强度等级,柱净高Hn (m),柱验算方向的截面高h (mm),柱验算方向截面宽b (mm),柱箍筋牌号,柱箍筋截面积Asv  (mm^2),柱箍筋间距s  (mm),柱下端纵向钢筋牌号,柱下端受压区纵向钢筋面积As'  (mm^2),柱下端受拉区纵向钢筋面积As  (mm^2),柱上端纵向钢筋牌号,柱上端受压区纵向钢筋面积As'  (mm^2),柱上端受拉区纵向钢筋面积As  (mm^2),受拉筋合力点到受拉边缘的距离as (mm),受压筋合力点距受压边缘的距离  as‘(mm),备注";
                    ExcelReaderUtil.checkTitle(file.getInputStream(),2,0,title);
                    ExcelResult excelResult = ExcelReaderUtil.readExcelBean(file.getInputStream(), RcpExcelSheet1Vo.class, 3, 0);
                    List<RcpExcelSheet1Vo> list = excelResult.getData();
                    if (PlatformObjectUtils.isNotEmpty(list)) {
                        Map<String, List<RcpExcelSheet1Vo>> sheet1Map = list.stream().collect(Collectors.groupingBy(RcpExcelSheet1Vo::getNumType));
                        mapList.add(sheet1Map);
                    }
                }
                if (numSheet == 1) {
                    String title = "建筑物序号,层数,柱编号,粱编号,梁截面宽度bL (mm),梁截面高度hL  (mm),梁的跨度L(mm),梁受拉钢筋牌号,梁有效高度(mm),梁受拉区纵筋面积As（mm^2）,梁受压区纵筋面积As'（mm^2）,梁有效高度(mm),梁受拉区纵筋面积As（mm^2）,梁受压区纵筋面积As'（mm^2）";
                    ExcelReaderUtil.checkTitle(file.getInputStream(),3,1,title);
                    ExcelResult excelResult = ExcelReaderUtil.readExcelBean(file.getInputStream(), RcpExcelSheet2Vo.class, 4, numSheet);
                    List<RcpExcelSheet2Vo> list = excelResult.getData();
                    if (PlatformObjectUtils.isNotEmpty(list)) {
                        Map<String, List<RcpExcelSheet2Vo>> sheet2Map = list.stream().collect(Collectors.groupingBy(RcpExcelSheet2Vo::getNumType));
                        mapList.add(sheet2Map);
                    }
                }
                if (numSheet == 2) {
                    String title = "建筑物序号,楼层号,填充墙编号,填充墙砌体类别,填充墙砂浆强度等级,b填充墙截面宽度(mm),h填充墙的高度(mm),t填充墙的厚度(mm)";
                    ExcelReaderUtil.checkTitle(file.getInputStream(),2,2,title);
                    ExcelResult excelResult = ExcelReaderUtil.readExcelBean(file.getInputStream(), RcpExcelSheet3Vo.class, 3, numSheet);
                    List<RcpExcelSheet3Vo> list = excelResult.getData();
                    if (PlatformObjectUtils.isNotEmpty(list)) {
                        Map<String, List<RcpExcelSheet3Vo>> sheet3Map = list.stream().collect(Collectors.groupingBy(RcpExcelSheet3Vo::getNumType));
                        mapList.add(sheet3Map);
                    } else {
                        mapList.add(2, null);
                    }
                }
                if (numSheet == 3) {
                    String title = "建筑物序号,楼层号,剪力墙编号,混凝土强度等级,抗震墙厚度(mm),抗震墙截面高度(mm),水平钢筋牌号,配置在同一水平截面内的水平钢筋截面面积（mm^2）,S2剪力墙水平向钢筋间距(mm),层高(m)";
                    ExcelReaderUtil.checkTitle(file.getInputStream(),2,3,title);
                    ExcelResult excelResult = ExcelReaderUtil.readExcelBean(file.getInputStream(), RcpExcelSheet4Vo.class, 3, numSheet);
                    List<RcpExcelSheet4Vo> list = excelResult.getData();
                    if (PlatformObjectUtils.isNotEmpty(list)) {
                        Map<String, List<RcpExcelSheet4Vo>> sheet4Map = list.stream().collect(Collectors.groupingBy(RcpExcelSheet4Vo::getNumType));
                        mapList.add(sheet4Map);
                    } else {
                        mapList.add(3, null);
                    }
                }
            }
        } catch (Exception e) {
            restResponse = RestResponse.fail(PlatformObjectUtils.isNotEmpty(e.getMessage()) ? e.getMessage() : "模板无数据，请检查模板!");
            return restResponse;
        }

        //直接计算
        //每个建筑的list
        try {
            //柱参数
            Map<String, List> map0 = mapList.get(0);
            //梁参数
            Map<String, List> map1 = mapList.get(1);
            //剪力墙参数
            Map<String, List> map2 = mapList.get(2);
            //填充墙参数
            Map<String, List> map3 = mapList.get(3);

            //将同一个建筑的参数放到一个list<list>中。
            for (Map.Entry<String, List> entry : map0.entrySet()) {

                ArrayList<List> perList = new ArrayList<>();
                perList.add(0, map0.get(entry.getKey()));
                perList.add(1, map1.get(entry.getKey()));
                if (PlatformObjectUtils.isNotEmpty(map2)) {
                    perList.add(2, map2.get(entry.getKey()));
                } else {
                    perList.add(2, null);
                }
                if (PlatformObjectUtils.isNotEmpty(map3)) {
                    perList.add(3, map3.get(entry.getKey()));
                } else {
                    perList.add(3, null);
                }
                restResponse = srcAnalyseService.calculate(perList);
                if (restResponse.getCode() != 200) {
                    break;
                }
            }
        } catch (Exception e) {
            restResponse = RestResponse.fail(PlatformObjectUtils.isNotEmpty(e.getMessage()) ? e.getMessage() : "导入失败!");
        }

        return restResponse;
        /*map0.forEach((key,value)->{
            RestResponse restResponse = null ;
            ArrayList<List>  perList = new ArrayList<>();
            perList.add(0,map0.get(key));
            perList.add(1,map1.get(key));
            perList.add(2,map2.get(key));
            perList.add(3,map3.get(key));
            //计算

            try {
                restResponse = srcAnalyseService.calculate(perList);
                if(restResponse.getCode() != 200){
                    throw  new Exception(restResponse.getMessage());
                }
            } catch (Exception e) {
                try {
                    throw  new Exception(restResponse.getMessage());
                } catch (Exception exception) {
                    exception.printStackTrace();
                }
            }


        });*/

        //解析完成之后做数据校验
        //rcpParameterVerification(mapList);
        //return RestResponse.succeed("导入成功!");

    }

/*    @Override
    public RestResponse uploadRcpInformation(MultipartFile file) {
        try {
            String user = sUserService.getSUser(PlatformSessionContext.getUserID());
            SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
            ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
            List<List<Object>> read = reader.read(18, reader.getRowCount());
            List<Object> title = reader.readRow(0);
            List<Object> secendTitle = reader.readRow(1);

            String titleName = "[序号, 区域, 区域, 区域, 用途, 用途, 结构类型, 建造年代, 设防情况, 层数, 是否对称配筋, 砌体类别, 砂浆强度, 备注, 场地类别, 设计地震分组, 阻尼比, 柱编号, 每榀间距（m）, 跨度, 层号, 剪力墙参数, 剪力墙参数, 剪力墙参数, 剪力墙参数, 榀数, 柱净高Hn, 柱截面宽b(mm), 柱截面高h(mm), 纵筋fyk\n" +
                    "(N/mm^2), 纵向受拉筋总截面积As\n" +
                    "(mm^2), 当框架为强梁弱柱型框架柱时，以下字段必填, 柱截面有效高(mm), 混凝土抗压强度标准值fck\n" +
                    "(N/mm^2), 界限受压区高度ζbk, 总跨度(m), 受压筋合理点距受压边缘的距离\n" +
                    "as(mm), 板厚(mm), 砼标号, fvk\n" +
                    "(N/mm^2), 箍筋间距s\n" +
                    "(mm), 箍筋截面积Asv, 剪力墙\n" +
                    "Ash, 剪力墙箍筋间距S2（mm）, 剪力墙箍筋标准值fyvk(mm), 砖填充墙水平截005面面积, 两侧是否有填充墙, 填充墙参数, 填充墙参数, 填充墙参数, 砌体强度的正压力影响系数   , 砖墙的抗剪强度标准值fvk, 抗震墙的截面积\n" +
                    "Aw, 水平钢筋截面面积\n" +
                    "Ash, 抗震墙的计算剪跨比      λ, 层高, 活荷载, 混凝土弹性模具Eb(mm), 边柱/中柱, 梁参数, 梁参数, 梁参数, 梁参数, 梁参数, 修正系数Ci, 修正系数Ci, 修正系数Ci, 修正系数Ci]";

            String secendTitleName = "[序号, 省份, 市, 区/县级, 类别, 类型, 结构类型, 建造年代, 设防情况, 层数, 是否对称配筋, 砌体类别, 砂浆强度, 备注, 场地类别, 设计地震分组, 阻尼比, 柱编号, 每榀间距（m）, 跨度, 层号, 剪力墙片数, 剪力墙层高（mm）, 剪力墙厚（mm）, 剪力墙宽度（mm）, 榀数, 柱净高Hn, 柱截面宽b(mm), 柱截面高h(mm), 纵筋fyk\n" +
                    "(N/mm^2), 纵向受拉筋总截面积As\n" +
                    "(mm^2), 纵向受压筋总截面积As’\n" +
                    "(mm^2), 柱截面有效高(mm), 混凝土抗压强度标准值fck\n" +
                    "(N/mm^2), 界限受压区高度ζbk, 总跨度(m), 受压筋合理点距受压边缘的距离\n" +
                    "as(mm), 板厚(mm), 砼标号, fvk\n" +
                    "(N/mm^2), 箍筋间距s\n" +
                    "(mm), 箍筋截面积Asv, 剪力墙\n" +
                    "Ash, 剪力墙箍筋间距S2（mm）, 剪力墙箍筋标准值fyvk(mm), 砖填充墙水平截面面积, 两侧是否有填充墙, 填充墙层高（mm）, 填充墙厚（mm), 填充墙宽度（mm), 砌体强度的正压力影响系数   , 砖墙的抗剪强度标准值fvk, 抗震墙的截面积\n" +
                    "Aw, 水平钢筋截面面积\n" +
                    "Ash, 抗震墙的计算剪跨比      λ, 层高, 活荷载, 混凝土弹性模具Eb(mm), 边柱/中柱, 梁编号, 梁高\n" +
                    "(mm), 梁截面高\n" +
                    "(mm), 梁截面宽\n" +
                    "(mm), 梁混凝土弹性模具, 现浇钢筋混凝土构件沿高度断面无突变, 平面对称, 施工质量良好, 建筑抗震设计规范]";
            if (!titleName.equals(title.toString()) && !secendTitleName.equals(secendTitle.toString())) {
                return RestResponse.fail("导入失败，请检查表头是否改动");
            }
            if (read.size() == 0) {
                return RestResponse.fail("导入失败，表格中无数据");
            }
            //数据校验
            //RestResponse rs = rcpParameterVerification(read.size(), read);

            *//*分建筑
            不同的建筑区域、用途、结构类型、年代、设防情况是不相同的
            将每个读取到的建筑基本信息放到一个List 中，然后每次存取数据的时候都要在map中查一下是否存在，如果存在就不需要新插入entirety数据，如果不存在就需要插入数据；
            *//*
            List entiretyList = new ArrayList();

           *//* if (rs.getCode() != 200) {
                return RestResponse.fail(rs.getMessage());
            }*//*

            RcpInformationEntity informationEntity = new RcpInformationEntity();
            ArrayList<RcpInformationEntity> dataList = new ArrayList<>();
            List<Map<String, Integer>> floorNums = new ArrayList<>();
            String columnId = "";
            String calId = "";
            StringBuffer calIds = new StringBuffer();
            String number = "";
            for (List<Object> objects : read) {
                String entiretyId = UUIDGenerator.getUUID();
                //如果是第一个行的话，就加一个整体参数
                if (read.indexOf(objects) == 0) {
                    CztCrsEntiretyCalResult entiretyCalResult = new CztCrsEntiretyCalResult();
                    calId = entiretyId;
                    calIds.append(calId);
                    entiretyCalResult.setCalId(entiretyId);
                    entiretyCalResult.setProvince(objects.get(1).toString());
                    entiretyCalResult.setCity(objects.get(2).toString());
                    entiretyCalResult.setCounty(objects.get(3).toString());
                    entiretyCalResult.setPurpose(objects.get(4).toString());
                    entiretyCalResult.setPurpose1(objects.get(5).toString());
                    entiretyCalResult.setDataType(FxfzConstants.CZT_GJHNT_INFO);
                    entiretyCalResult.setStructureType("钢筋混凝土结构");
                    entiretyCalResult.setStructureType(objects.get(6).toString());
                    entiretyCalResult.setYears(objects.get(7).toString());
                    entiretyCalResult.setFortification(objects.get(8).toString());
                    entiretyCalResult.setCs(objects.get(9).toString());

                    entiretyCalResult.setBwCategory(objects.get(11).toString());
                    entiretyCalResult.setRemark(objects.get(13).toString());
                    entiretyCalResult.setSc(objects.get(14).toString());
                    entiretyCalResult.setEqGroup(objects.get(15).toString());
                    entiretyCalResult.setDampRatio(Double.parseDouble(objects.get(16).toString()));
                    entiretyCalResult.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                    entiretyCalResult.setCreateUserId(PlatformSessionContext.getUserID());
                    entiretyCalResult.setUserName(sUser.getUserName());
                    entiretyCalResult.setDelFlag("0");
                    entiretyCalResult.setBasicLibrary("0");
                    String type1 = "钢筋混凝土结构";
                    String type2 = "";
                    if (entiretyCalResult.getStructureType().equals("钢筋混凝框架结构")) {
                        type2 = "框架结构";
                    } else if (entiretyCalResult.getStructureType().equals("钢筋混凝框架-剪力墙结构")) {
                        type2 = "框架-剪力墙结构";
                    } else if (entiretyCalResult.getStructureType().equals("钢筋混凝土剪力墙结构")) {
                        type2 = "剪力墙结构";
                    }
                    entiretyCalResult.setNumber(generationNumberUtil.getCityInitials(entiretyCalResult.getProvince()) +
                            generationNumberUtil.type(type1, type2) +
                            generationNumberUtil.getFs(entiretyCalResult.getFortification()) +
                            srcAnaluseUtils.getNumnerFromDatabase());
                    number = entiretyCalResult.getNumber();
                    entiretyCalResult.setSerialNum(PlatformObjectUtils.isNotEmpty(crsEntiretyCalResultRepository.findMaxNum()) ? crsEntiretyCalResultRepository.findMaxNum() + 1 : 1);
                    entiretyCalResult.setCalculate_or_not("0");

                    entiretyCalResult.setCiType1("现浇钢筋混凝土构件沿高度断面无突变");
                    entiretyCalResult.setCiType1Value(objects.get(64).toString().equals("满足") ? 0 : 1);

                    entiretyCalResult.setCiType2("平面对称");
                    entiretyCalResult.setCiType2Value(objects.get(65).toString().equals("对称") ? 0 : 1);

                    entiretyCalResult.setCiType3("施工质量良好");
                    entiretyCalResult.setCiType3Value(objects.get(66).toString().equals("满足") ? 0 : 1);

                    entiretyCalResult.setCiType4("建筑抗震设计规范");
                    entiretyCalResult.setCiType4Value(CorrectionCiEnum.getByValue(objects.get(67).toString()));

                    CStructureCiEntity ciType1 = rcStructureRepository.getCStructureCiByCondition(entiretyCalResult.getCiType1(), objects.get(64).toString(), entiretyCalResult.getCiType1Value());
                    CStructureCiEntity ciType2 = rcStructureRepository.getCStructureCiByCondition(entiretyCalResult.getCiType2(), objects.get(65).toString().equals("对称") ? "满足" : "不满足", entiretyCalResult.getCiType2Value());
                    CStructureCiEntity ciType3 = rcStructureRepository.getCStructureCiByCondition(entiretyCalResult.getCiType3(), objects.get(66).toString(), entiretyCalResult.getCiType3Value());
                    CStructureCiEntity ciType4 = rcStructureRepository.getCStructureCiByCondition(entiretyCalResult.getCiType4(), objects.get(67).toString(), entiretyCalResult.getCiType4Value());

                    String ciIdsArr = ciType1.getCcsrId() + "," + ciType2.getCcsrId() + "," + ciType3.getCcsrId() + "," + ciType4.getCcsrId();
                    for (String ciId : ciIdsArr.split(",")) {
                        CztCrsEntiretyCi cztCrsEntiretyCi = new CztCrsEntiretyCi();
                        cztCrsEntiretyCi.setId(UUIDGenerator.getUUID());
                        cztCrsEntiretyCi.setDelFlag("0");
                        cztCrsEntiretyCi.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                        cztCrsEntiretyCi.setCreateUser(PlatformSessionContext.getUserID());
                        cztCrsEntiretyCi.setEntiretyId(entiretyId);
                        cztCrsEntiretyCi.setCiId(ciId);
                        ciRepository.save(cztCrsEntiretyCi);
                    }

                    crsEntiretyCalResultRepository.save(entiretyCalResult);
                    StringBuffer entiretySb = new StringBuffer();
                    entiretySb = entiretySb.append(entiretyCalResult.getProvince()).append(entiretyCalResult.getCity()).append(entiretyCalResult.getCounty());
                    entiretySb = entiretySb.append(entiretyCalResult.getPurpose()).append(entiretyCalResult.getPurpose1())
                            .append(entiretyCalResult.getStructureType1())*//*.append(entiretyCalResult.getStructureType1())*//*
                            .append(entiretyCalResult.getYears()).append(entiretyCalResult.getFortification());

                    entiretyList.add(entiretySb.toString());
                }
//                如果不是第一行就需要判断之前是否存在这个建筑。如果不存在则需要新增；
                else {
                    StringBuffer entiretySb = new StringBuffer();
                    entiretySb = entiretySb.append(objects.get(1).toString()).append(objects.get(2).toString())
                            .append(objects.get(3).toString()).append(objects.get(4).toString()).append(objects.get(5).toString())
                            .append(objects.get(6).toString()).append(objects.get(7).toString()).append(objects.get(8).toString());
                    if (!entiretyList.contains(entiretySb.toString())) {
                        calId = entiretyId;
                        CztCrsEntiretyCalResult entiretyCalResult = new CztCrsEntiretyCalResult();
                        entiretyCalResult.setCalId(entiretyId);
                        entiretyCalResult.setProvince(objects.get(1).toString());
                        entiretyCalResult.setCity(objects.get(2).toString());
                        entiretyCalResult.setCounty(objects.get(3).toString());
                        entiretyCalResult.setPurpose(objects.get(4).toString());
                        entiretyCalResult.setPurpose1(objects.get(5).toString());
                        entiretyCalResult.setDataType(FxfzConstants.CZT_GJHNT_INFO);
                        entiretyCalResult.setStructureType("钢筋混凝土结构");
                        entiretyCalResult.setStructureType1(objects.get(6).toString());
                        entiretyCalResult.setYears(objects.get(7).toString());
                        entiretyCalResult.setFortification(objects.get(8).toString());
                        entiretyCalResult.setCs(objects.get(9).toString());

                        entiretyCalResult.setBwCategory(objects.get(11).toString());
                        entiretyCalResult.setRemark(objects.get(13).toString());
                        entiretyCalResult.setSc(objects.get(14).toString());
                        entiretyCalResult.setEqGroup(objects.get(15).toString());
                        entiretyCalResult.setDampRatio(Double.parseDouble(objects.get(16).toString()));
                        entiretyCalResult.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                        entiretyCalResult.setCreateUserId(PlatformSessionContext.getUserID());
                        entiretyCalResult.setUserName(sUser.getUserName());
                        entiretyCalResult.setDelFlag("0");
                        entiretyCalResult.setBasicLibrary("0");
                        String type1 = "钢筋混凝土结构";
                        String type2 = "";
                        if (entiretyCalResult.getStructureType().equals("钢筋混凝框架结构")) {
                            type2 = "框架结构";
                        } else if (entiretyCalResult.getStructureType().equals("钢筋混凝框架-剪力墙结构")) {
                            type2 = "框架-剪力墙结构";
                        } else if (entiretyCalResult.getStructureType().equals("钢筋混凝土剪力墙结构")) {
                            type2 = "剪力墙结构";
                        }
                        entiretyCalResult.setNumber(generationNumberUtil.getCityInitials(entiretyCalResult.getProvince()) +
                                generationNumberUtil.type(type1, type2) +
                                generationNumberUtil.getFs(entiretyCalResult.getFortification()) +
                                srcAnaluseUtils.getNumnerFromDatabase());
                        number = entiretyCalResult.getNumber();
                        entiretyCalResult.setSerialNum(PlatformObjectUtils.isNotEmpty(crsEntiretyCalResultRepository.findMaxNum()) ? crsEntiretyCalResultRepository.findMaxNum() + 1 : 1);
                        entiretyCalResult.setCalculate_or_not("0");

                        entiretyCalResult.setCiType1("现浇钢筋混凝土构件沿高度断面无突变");
                        entiretyCalResult.setCiType1Value(objects.get(64).toString().equals("满足") ? 0 : 1);

                        entiretyCalResult.setCiType2("平面对称");
                        entiretyCalResult.setCiType2Value(objects.get(65).toString().equals("对称") ? 0 : 1);

                        entiretyCalResult.setCiType3("施工质量良好");
                        entiretyCalResult.setCiType3Value(objects.get(66).toString().equals("满足") ? 0 : 1);

                        entiretyCalResult.setCiType4("建筑抗震设计规范");
                        entiretyCalResult.setCiType4Value(CorrectionCiEnum.getByValue(objects.get(67).toString()));

                     *//*   CStructureCiEntity ciType1 = rcStructureRepository.getCStructureCiByCondition(entiretyCalResult.getCiType1(), objects.get(64).toString(), entiretyCalResult.getCiType1Value());
                        CStructureCiEntity ciType2 = rcStructureRepository.getCStructureCiByCondition(entiretyCalResult.getCiType2(), objects.get(65).toString().equals("对称") ? "满足" : "不满足", entiretyCalResult.getCiType2Value());
                        CStructureCiEntity ciType3 = rcStructureRepository.getCStructureCiByCondition(entiretyCalResult.getCiType3(), objects.get(66).toString(), entiretyCalResult.getCiType3Value());
                        CStructureCiEntity ciType4 = rcStructureRepository.getCStructureCiByCondition(entiretyCalResult.getCiType4(), objects.get(67).toString(), entiretyCalResult.getCiType4Value());
//                        String ciIdsArr = ciType1.getCcsrId() + "," + ciType2.getCcsrId() + "," + ciType3.getCcsrId() + "," + ciType4.getCcsrId();
//                        saveEntivityC(entiretyId);
                        CztCrsEntiretyCi cztCrsEntiretyCi = new CztCrsEntiretyCi();
                        cztCrsEntiretyCi.setId(UUIDGenerator.getUUID());
                        cztCrsEntiretyCi.setDelFlag("0");
                        cztCrsEntiretyCi.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                        cztCrsEntiretyCi.setCreateUser(PlatformSessionContext.getUserID());
                        cztCrsEntiretyCi.setEntiretyId(entiretyId);
                        cztCrsEntiretyCi.setCiId(ciType.getCcsrId());
                        cztCrsEntiretyCi.setCondition(ciType.getCondition());
                        cztCrsEntiretyCi.setCiType();
                        ciRepository.save(cztCrsEntiretyCi);*//*

                        crsEntiretyCalResultRepository.save(entiretyCalResult);
                        entiretyList.add(entiretySb.toString());
                    }
                }
                //如果行数是4的倍数，那新增柱子
                if (read.indexOf(objects) % 4 == 0) {
                    RcpInformationEntity rcpInformationEntity = new RcpInformationEntity();
                    columnId = UUIDGenerator.getUUID();
                    rcpInformationEntity.setCcpiId(columnId);
                    rcpInformationEntity.setPillarCode(objects.get(17).toString());
                    rcpInformationEntity.setEntiretyId(calId);
                    rcpInformationEntity.setTrussSpacing(Double.parseDouble(objects.get(18).toString()));
                    rcpInformationEntity.setSpan(Double.parseDouble(objects.get(19).toString()));
                    int floorNum = Integer.parseInt(objects.get(20).toString());
                    rcpInformationEntity.setShearWallPieces(Double.parseDouble(objects.get(21).toString()));
                    rcpInformationEntity.setShearWallFloorHeight(Double.parseDouble(objects.get(22).toString()));
                    rcpInformationEntity.setShearWallThickness(Double.parseDouble(objects.get(23).toString()));
                    rcpInformationEntity.setShearWallWidth(Double.parseDouble(objects.get(24).toString()));
                    rcpInformationEntity.setNumberOfPieces(Integer.parseInt(objects.get(25).toString()));
                    Map floorMap = new HashMap();
                    floorMap.put(calId, floorNum);
                    if (!floorNums.contains(floorMap)) {
                        floorNums.add(floorMap);
                        CztCrsStoreyCalResult storeyCalResult = new CztCrsStoreyCalResult();
                        storeyCalResult.setEntiretyId(calId);
                        storeyCalResult.setFloorNum(floorNum);
                        storeyCalResult.setCalId(UUIDGenerator.getUUID());
                        storeyCalResult.setLiveLoad(Double.parseDouble(objects.get(56).toString()));
                        storeyCalResult.setDelFlag("2");
                        storeyCalResult.setFloorHeight(Double.parseDouble(objects.get(26).toString()));
                        *//*storeyCalResult.setShearWallPieces(Double.parseDouble(objects.get(21).toString()));
                        storeyCalResult.setShearWallFloorHeight(Double.parseDouble(objects.get(22).toString()));
                        storeyCalResult.setShearWallThickness(Double.parseDouble(objects.get(23).toString()));
                        storeyCalResult.setShearWallWidth(Double.parseDouble(objects.get(24).toString()));*//*
                        storeyCalResult.setNumberOfPieces(Integer.parseInt(objects.get(25).toString()));

                        crsStoreyCalResultRespository.save(storeyCalResult);
                    }
                    rcpInformationEntity.setFloorNum(floorNum);

                    rcpInformationEntity.setPillarHeight(Double.parseDouble(objects.get(26).toString()));
                    rcpInformationEntity.setPillarSectionWidth(Double.parseDouble(objects.get(27).toString()));
                    rcpInformationEntity.setPillarSectionHeight(Double.parseDouble(objects.get(28).toString()));
                    rcpInformationEntity.setFyk(Double.parseDouble(objects.get(29).toString()));
                    rcpInformationEntity.setPortraitSectionalArea(Double.parseDouble(objects.get(30).toString()));
                    rcpInformationEntity.setLongitudinalCompressiveArea(Double.parseDouble(objects.get(31).toString()));

                    rcpInformationEntity.setH0(Double.parseDouble(objects.get(32).toString()));
                    rcpInformationEntity.setFck(Double.parseDouble(objects.get(33).toString()));
                    rcpInformationEntity.setBk(Double.parseDouble(objects.get(34).toString()));
                    rcpInformationEntity.setTotalSpan(Double.parseDouble(objects.get(35).toString()));
                    rcpInformationEntity.setDistance(Double.parseDouble(objects.get(36).toString()));
                    rcpInformationEntity.setBoardThickness(Double.parseDouble(objects.get(37).toString()));
                    rcpInformationEntity.setConcreteCode(Double.parseDouble(objects.get(38).toString()));
                    rcpInformationEntity.setFvk(Double.parseDouble(objects.get(39).toString()));
                    rcpInformationEntity.setSpacing(Double.parseDouble(objects.get(40).toString()));
                    rcpInformationEntity.setSectionalArea(Double.parseDouble(objects.get(41).toString()));
                    rcpInformationEntity.setAsh(Double.parseDouble(objects.get(42).toString()));
                    rcpInformationEntity.setS2(Double.parseDouble(objects.get(43).toString()));
                    rcpInformationEntity.setFyvk(Double.parseDouble(objects.get(44).toString()));
                    rcpInformationEntity.setAm(Double.parseDouble(objects.get(45).toString()));
                    rcpInformationEntity.setHasTcq(objects.get(46).toString());
                    rcpInformationEntity.setInfilledWallLayerHeight(Double.parseDouble(objects.get(47).toString()));
                    rcpInformationEntity.setInfilledWallThickness(Double.parseDouble(objects.get(48).toString()));
                    rcpInformationEntity.setFilledWallWidth(Double.parseDouble(objects.get(49).toString()));

                    rcpInformationEntity.setEn(Double.parseDouble(objects.get(50).toString()));
                    rcpInformationEntity.setFvkStrength(Double.parseDouble(objects.get(51).toString()));
                    rcpInformationEntity.setWallSectionalArea(Double.parseDouble(objects.get(52).toString()));
                    rcpInformationEntity.setSectionalAsh(Double.parseDouble(objects.get(53).toString()));
                    rcpInformationEntity.setJkb(Double.parseDouble(objects.get(54).toString()));
                    rcpInformationEntity.setFloorHeight(Double.parseDouble(objects.get(55).toString()));
                    rcpInformationEntity.setLiveLoad(Double.parseDouble(objects.get(56).toString()));
                    rcpInformationEntity.setEb(objects.get(57).toString());
                    rcpInformationEntity.setPillarPosition(objects.get(58).toString());
                    rcpInformationEntity.setCreateUser(PlatformSessionContext.getUserID());
                    rcpInformationEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                    rcpInformationEntity.setUserName(sUser.getUserName());
                    rcpInformationEntity.setDelFlag(YNEnum.N.toString());
                    rcpInformationEntity.setDataType(FxfzConstants.CZT_GJHNT_INFO);
                    rcpRepository.save(rcpInformationEntity);
                    informationEntity = rcpInformationEntity;
                }
                CztCrsCalRoofbeamResult roofBeam = new CztCrsCalRoofbeamResult();
                roofBeam.setCalId(UUIDGenerator.getUUID());
                roofBeam.setColumnId(informationEntity.getCcpiId());
                roofBeam.setColumnNum(informationEntity.getPillarCode());
                roofBeam.setDelFlag("1");
                roofBeam.setEntiretyId(calId);
                roofBeam.setBeamNum(number);
                roofBeam.setBeamNum(objects.get(59).toString());
                //roofBeam.setBeamHeigth(Double.parseDouble(objects.get(60).toString()));
                roofBeam.setBeamSectionHeight(Double.parseDouble(objects.get(61).toString()));
                roofBeam.setBeamSectionWidth(Double.parseDouble(objects.get(62).toString()));
                //roofBeam.setEl(objects.get(63).toString());
                roofbeamCalRepository.save(roofBeam);
            }
//            导入之后计算
            srcAnalyseService.reCalculates(calIds.toString());
            Map<String, List> stringListMap = srcAnalyseService.queryResult(calId);
            return RestResponse.succeed(stringListMap);
        } catch (Exception e) {
            String message = "模板数据异常,请检查!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }*/


    private void rcpParameterVerification(List<Map> mapList) throws Exception {
        //1 需要校验是否同一建筑物中柱编号是否重复
       /* for (Map map:mapList) {
            map.forEach((key,value) ->{

            });
        }*/
        //2 需要校验柱编号的合法性，梁编号以及填充墙编号、剪力墙编号的合法性 并且与层数的合法性 ；


        //3、需要校验numType 与省市县以及用途、结构类型、年代、设防情况、层数等的一致性 ；


        //

    }

    private RestResponse rcpParameterVerificationOld(int size, List<List<Object>> data) {
        for (int i = 0; i < size; i++) {
            List<Object> objects = data.get(i);
         /*   if (StringUtils.isBlank(objects.get(1).toString())) return RestResponse.fail("第" + (i + 3) + "行的{烈度}不能为空！");
            if (StringUtils.isBlank(objects.get(2).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{破坏程度}不能为空！");*/
            if (StringUtils.isBlank(objects.get(1).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{省份}不能为空！");
            if (StringUtils.isBlank(objects.get(2).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{市}不能为空！");
            if (StringUtils.isBlank(objects.get(3).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{区县}不能为空！");
            if (StringUtils.isBlank(objects.get(4).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{用途}不能为空！");
            if (StringUtils.isBlank(objects.get(5).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{用途}不能为空！");
            if (StringUtils.isBlank(objects.get(6).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{结构类型}不能为空！");
            if (StringUtils.isBlank(objects.get(7).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{建造年代}不能为空！");
            if (StringUtils.isBlank(objects.get(8).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{设防情况}不能为空！");
            if (StringUtils.isBlank(objects.get(9).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{层数}不能为空！");

            if (StringUtils.isBlank(objects.get(10).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{是否对称配筋}不能为空！");
            if (StringUtils.isBlank(objects.get(11).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{砌体类别}不能为空！");
            if (StringUtils.isBlank(objects.get(12).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{砂浆强度}不能为空！");
            if (StringUtils.isBlank(objects.get(14).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{场地类别}不能为空！");
            if (StringUtils.isBlank(objects.get(15).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{设计地震分组}不能为空！");
            if (StringUtils.isBlank(objects.get(16).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{阻尼比}不能为空！");
            if (StringUtils.isBlank(objects.get(17).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{柱编号}不能为空！");
            if (StringUtils.isBlank(objects.get(18).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{每榀间距（m）}不能为空！");
            if (StringUtils.isBlank(objects.get(19).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{跨度}不能为空！");
            if (StringUtils.isBlank(objects.get(20).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{层号}不能为空！");
            if (StringUtils.isBlank(objects.get(25).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{榀数}不能为空！");
            if (StringUtils.isBlank(objects.get(26).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{柱净高Hn}不能为空！");
            if (StringUtils.isBlank(objects.get(27).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{柱截面宽b(mm)}不能为空！");
            if (StringUtils.isBlank(objects.get(28).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{柱截面高h(mm)}不能为空！");
            if (StringUtils.isBlank(objects.get(29).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{纵筋fyk}不能为空！");
            if (StringUtils.isBlank(objects.get(30).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{纵向受拉筋总截面积As}不能为空！");
            if (StringUtils.isBlank(objects.get(32).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{柱截面有效高}不能为空！");
            if (StringUtils.isBlank(objects.get(33).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{混凝土抗压强度标准值fck}不能为空！");
            if (StringUtils.isBlank(objects.get(34).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{界限受压区高度ζbk}不能为空！");
            if (StringUtils.isBlank(objects.get(35).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{总跨度}不能为空！");
            if (StringUtils.isBlank(objects.get(36).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{受压筋合理点距受压边缘的距离as}不能为空！");
            if (StringUtils.isBlank(objects.get(37).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{板厚}不能为空！");
            if (StringUtils.isBlank(objects.get(38).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{砼标号}不能为空！");
            if (StringUtils.isBlank(objects.get(39).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{fvk}不能为空！");
            if (StringUtils.isBlank(objects.get(40).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{箍筋间距s}不能为空！");
            if (StringUtils.isBlank(objects.get(41).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{箍筋截面积Asv}不能为空！");
            if (StringUtils.isBlank(objects.get(42).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{剪力墙Ash}不能为空！");
            if (StringUtils.isBlank(objects.get(43).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{剪力墙箍筋间距S2}不能为空！");
            if (StringUtils.isBlank(objects.get(44).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{剪力墙箍筋标准值fyvk}不能为空！");
            if (StringUtils.isBlank(objects.get(45).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{砖填充墙水平截面面积}不能为空！");
            if (StringUtils.isBlank(objects.get(46).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{两侧是否有填充墙}不能为空！");
            if (objects.get(46).toString().equals("是")) {
                if (StringUtils.isBlank(objects.get(47).toString()))
                    return RestResponse.fail("第" + (i + 18) + "行的{填充墙层高}不能为空！");
                if (StringUtils.isBlank(objects.get(48).toString()))
                    return RestResponse.fail("第" + (i + 18) + "行的{填充墙厚}不能为空！");
                if (StringUtils.isBlank(objects.get(49).toString()))
                    return RestResponse.fail("第" + (i + 18) + "行的{填充墙宽度}不能为空！");
            }
            if (StringUtils.isBlank(objects.get(50).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{砌体强度的正压力影响系数}不能为空！");
            if (StringUtils.isBlank(objects.get(51).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{砖墙的抗剪强度标准值fvk}不能为空！");
            if (StringUtils.isBlank(objects.get(52).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{抗震墙的截面积Aw}不能为空！");
            if (StringUtils.isBlank(objects.get(53).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{水平钢筋截面面积Ash}不能为空！");
            if (StringUtils.isBlank(objects.get(54).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{抗震墙的计算剪跨比}不能为空！");
            if (StringUtils.isBlank(objects.get(55).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{层高}不能为空！");
            if (StringUtils.isBlank(objects.get(56).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{活荷载}不能为空！");
            if (StringUtils.isBlank(objects.get(57).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{混凝土弹性模具Eb}不能为空！");
            if (StringUtils.isBlank(objects.get(58).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{边柱/中柱}不能为空！");
            if (StringUtils.isBlank(objects.get(59).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{梁编号}不能为空！");
            if (StringUtils.isBlank(objects.get(60).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{梁高}不能为空！");
            if (StringUtils.isBlank(objects.get(61).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{梁截面高}不能为空！");
            if (StringUtils.isBlank(objects.get(62).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{梁界面宽}不能为空！");
            if (StringUtils.isBlank(objects.get(63).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{梁混凝土弹性模具}不能为空！");
            if (StringUtils.isBlank(objects.get(64).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{现浇钢筋混凝土构件沿高度断面无突变}不能为空！");
            if (StringUtils.isBlank(objects.get(65).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{平面对称}不能为空！");
            if (StringUtils.isBlank(objects.get(66).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{施工质量良好}不能为空！");
            if (StringUtils.isBlank(objects.get(67).toString()))
                return RestResponse.fail("第" + (i + 18) + "行的{建筑抗震设计规范}不能为空！");
        }
        return RestResponse.succeed();
    }

    @Override
    public RestResponse uploadHbpInformation(MultipartFile file) {
        try {
            String user = sUserService.getSUser(PlatformSessionContext.getUserID());
            SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
            ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
            List<List<Object>> read = reader.read(3, reader.getRowCount());
            List<Object> title = reader.readRow(1);
            String titleName = "[序号, 省份, 市, 区/县级, 用途, 用途, 结构类型, 建造年代, 设防情况, 层数, 场地类别, 建筑面积, 建筑高度, 层高, 6度下弹性最大层间位移角, 7度下弹性最大层间位移角, 8度下弹性最大层间位移角, 9度下弹性最大层间位移角, 10度下弹性最大层间位移角]";
            if (!titleName.equals(title.toString())) {
                return RestResponse.fail("导入失败，请检查表头是否改动");
            }
            if (read.size() == 0) {
                return RestResponse.fail("导入失败，表格中无数据");
            }
            //数据校验
            RestResponse rs = hbpParameterVerification(read.size(), read);
            if (rs.getCode() != 200) {
                return RestResponse.fail(rs.getMessage());
            }
            ArrayList<HbpInfoEntity> dataList = new ArrayList<>();
            read.forEach(objects -> {
                HbpInfoEntity hbpInfoEntity = new HbpInfoEntity();
                hbpInfoEntity.setChbpiId(UUIDGenerator.getUUID());
                hbpInfoEntity.setProvince(objects.get(1).toString());
                hbpInfoEntity.setCity(objects.get(2).toString());
                hbpInfoEntity.setCounty(objects.get(3).toString());
                hbpInfoEntity.setPurpose(objects.get(4).toString());
                hbpInfoEntity.setPurpose1(objects.get(5).toString());
                hbpInfoEntity.setStructureType("钢筋混凝土结构");
                hbpInfoEntity.setStructureType1(objects.get(6).toString());

                hbpInfoEntity.setYears(objects.get(7).toString());
                hbpInfoEntity.setFortification(objects.get(8).toString());
                hbpInfoEntity.setCs(objects.get(9).toString());
                hbpInfoEntity.setSite(objects.get(10).toString());
                hbpInfoEntity.setBuildArea(ImportDataServiceImpl.getBigDecimal(objects.get(11).toString()));
                hbpInfoEntity.setBuildingHeight(ImportDataServiceImpl.getBigDecimal(objects.get(12).toString()));
                hbpInfoEntity.setFloorHeight(ImportDataServiceImpl.getBigDecimal(objects.get(13).toString()));
                hbpInfoEntity.setTxzdcjwyj6(ImportDataServiceImpl.getBigDecimal(objects.get(14).toString()));
                hbpInfoEntity.setTxzdcjwyj7(ImportDataServiceImpl.getBigDecimal(objects.get(15).toString()));
                hbpInfoEntity.setTxzdcjwyj8(ImportDataServiceImpl.getBigDecimal(objects.get(16).toString()));
                hbpInfoEntity.setTxzdcjwyj9(ImportDataServiceImpl.getBigDecimal(objects.get(17).toString()));
                hbpInfoEntity.setTxzdcjwyj10(ImportDataServiceImpl.getBigDecimal(objects.get(18).toString()));
                hbpInfoEntity.setCreateUser(PlatformSessionContext.getUserID());
                hbpInfoEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                hbpInfoEntity.setDelFlag(YNEnum.N.toString());
                hbpInfoEntity.setBasicLibrary("0");
                hbpInfoEntity.setDataType(FxfzConstants.CZT_GCJZW_INFO);
                hbpInfoEntity.setUserName(sUser.getUserName());
                String number = generationNumberUtil.getCityInitials(hbpInfoEntity.getProvince()) + "-" +
                        generationNumberUtil.type(hbpInfoEntity.getStructureType(), "") + "-" +
                        generationNumberUtil.getFs(hbpInfoEntity.getFortification()) + "-" + this.getNumber(RedisKeyConstants.CZT_GCJZCS_KEY);
                hbpInfoEntity.setNumber(number);
                dataList.add(hbpInfoEntity);
            });
            //计算
            dataList.forEach(it -> {
                it.setCalculateOrNot("1");
                HashMap<Integer, BigDecimal> paramMap = new HashMap<>();
                paramMap.put(6,it.getTxzdcjwyj6());
                paramMap.put(7,it.getTxzdcjwyj7());
                paramMap.put(8,it.getTxzdcjwyj8());
                paramMap.put(9,it.getTxzdcjwyj9());
                paramMap.put(10,it.getTxzdcjwyj10());
                HashMap<Integer, Object> value = fshBuildingsService.getValue(paramMap, it.getStructureType1());
                saveResult(value,it);
                bacInformationRepository.saveCountHbpInfo(it);
            });
            return RestResponse.succeed("导入成功!");
        } catch (IOException e) {
            String message = "导入失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    private void saveResult(HashMap<Integer, Object> map,HbpInfoEntity entity){
        StringBuilder ids = new StringBuilder();
        HashMap<String, Object> value6 = (HashMap<String, Object>) map.get(6);
        entity.setForecastResults6(value6.get("value").toString());
        entity.setEmidAngle6(value6.get("as").toString());
        ids.append(value6.get("correctionCoefficient").toString()+",");
        HashMap<String, Object> value7 = (HashMap<String, Object>) map.get(7);
        entity.setForecastResults7(value7.get("value").toString());
        entity.setEmidAngle7(value7.get("as").toString());
        ids.append(value7.get("correctionCoefficient").toString()+",");
        HashMap<String, Object> value8 = (HashMap<String, Object>) map.get(8);
        entity.setForecastResults8(value8.get("value").toString());
        entity.setEmidAngle8(value8.get("as").toString());
        ids.append(value8.get("correctionCoefficient").toString()+",");
        HashMap<String, Object> value9 = (HashMap<String, Object>) map.get(9);
        entity.setForecastResults9(value9.get("value").toString());
        entity.setEmidAngle9(value9.get("as").toString());
        ids.append(value9.get("correctionCoefficient").toString()+",");
        HashMap<String, Object> value10 = (HashMap<String, Object>) map.get(10);
        entity.setForecastResults10(value10.get("value").toString());
        entity.setEmidAngle10(value10.get("as").toString());
        ids.append(value10.get("correctionCoefficient").toString()+",");
        entity.setCorrectionCoefficient(ids.toString());
    }

    private RestResponse hbpParameterVerification(int size, List<List<Object>> data) {
        for (int i = 0; i < size; i++) {
            List<Object> objects = data.get(i);
            if (StringUtils.isBlank(objects.get(1).toString()))
                return RestResponse.fail("第" + (i + 4) + "行的{省份}不能为空！");
            if (StringUtils.isBlank(objects.get(2).toString()))
                return RestResponse.fail("第" + (i + 4) + "行的{市}不能为空！");
            if (StringUtils.isBlank(objects.get(3).toString()))
                return RestResponse.fail("第" + (i + 4) + "行的{区县}不能为空！");
            if (StringUtils.isBlank(objects.get(4).toString()))
                return RestResponse.fail("第" + (i + 4) + "行的{用途}不能为空！");
            if (StringUtils.isBlank(objects.get(5).toString()))
                return RestResponse.fail("第" + (i + 4) + "行的{用途}不能为空！");
            if (StringUtils.isBlank(objects.get(6).toString()))
                return RestResponse.fail("第" + (i + 4) + "行的{结构类型}不能为空！");
            if (StringUtils.isBlank(objects.get(7).toString()))
                return RestResponse.fail("第" + (i + 4) + "行的{建造年代}不能为空！");
            if (StringUtils.isBlank(objects.get(8).toString()))
                return RestResponse.fail("第" + (i + 4) + "行的{设防情况}不能为空！");
            if (StringUtils.isBlank(objects.get(9).toString()))
                return RestResponse.fail("第" + (i + 4) + "行的{层数}不能为空！");
            if (StringUtils.isBlank(objects.get(10).toString()))
                return RestResponse.fail("第" + (i + 4) + "行的{场地类别}不能为空！");
            if (StringUtils.isBlank(objects.get(11).toString()))
                return RestResponse.fail("第" + (i + 4) + "行的{建筑面积}不能为空！");
            if (StringUtils.isBlank(objects.get(12).toString()))
                return RestResponse.fail("第" + (i + 4) + "行的{建筑高度}不能为空！");
            if (StringUtils.isBlank(objects.get(13).toString()))
                return RestResponse.fail("第" + (i + 4) + "行的{层高}不能为空！");
            if (StringUtils.isBlank(objects.get(14).toString()))
                return RestResponse.fail("第" + (i + 4) + "行的{地震作用}不能为空！");
            if (StringUtils.isBlank(objects.get(15).toString()))
                return RestResponse.fail("第" + (i + 4) + "行的{弹性最大层间位移角}不能为空！");
        }
        return RestResponse.succeed();
    }

    @Override
    public RestResponse uploadPsaData(MultipartFile file) {
        try {
            String user = sUserService.getSUser(PlatformSessionContext.getUserID());
            SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
            ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
            List<List<Object>> read = reader.read(1, reader.getRowCount());
            List<Object> title = reader.readRow(0);
            String titleName = "[序号, 地震动参数, 结构响应参数(单位g)]";
            if (!titleName.equals(title.toString())) {
                return RestResponse.fail("导入失败，请检查表头是否改动");
            }
            if (read.size() == 0) {
                return RestResponse.fail("导入失败，表格中无数据");
            }
            //数据校验
            RestResponse rs = psaParameterVerification(read.size(), read);
            if (rs.getCode() != 200) {
                return RestResponse.fail(rs.getMessage());
            }
            for (List<Object> datum : read) {
                CpvAnalysisEntity cpvAnalysisEntity = new CpvAnalysisEntity();
                cpvAnalysisEntity.setCpvaId(UUIDGenerator.getUUID());
                cpvAnalysisEntity.setDzdParams(new BigDecimal(datum.get(1).toString()));
                cpvAnalysisEntity.setResponseParams(new BigDecimal(datum.get(2).toString()));
                cpvAnalysisEntity.setCreateUser(PlatformSessionContext.getUserID());
                cpvAnalysisEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                cpvAnalysisEntity.setDelFlag(YNEnum.N.toString());
                cpvAnalysisEntity.setDataType(FxfzConstants.CZT_GLDZ_INFO);
                cpvAnalysisEntity.setUserName(sUser.getUserName());
                cpvAnalysisEntity.setNumber(cpvAnalysisEntity.getCpvaId());
                bacInformationRepository.savePsaData(cpvAnalysisEntity);
            }
            return RestResponse.succeed("导入成功!");
        } catch (IOException e) {
            String message = "导入失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    @Override
    public RestResponse saveCpvInfoEntity(CpvInfoEntity entity) {
        try {
            entity.setCpviId(UUIDGenerator.getUUID());
            entity.setCreateUser(PlatformSessionContext.getUserID());
            entity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
            entity.setDelFlag(YNEnum.N.toString());
            bacInformationRepository.saveCpvInfoEntity(entity);
            return RestResponse.succeed(entity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return RestResponse.fail("保存失败！");
    }

    @Override
    public RestResponse saveCpvAnalysis(CpvAnalysisEntity entity) {
        try {
            entity.setCpvaId(UUIDGenerator.getUUID());
            entity.setCreateUser(PlatformSessionContext.getUserID());
            entity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
            entity.setDelFlag(YNEnum.N.toString());
            bacInformationRepository.savePsaData(entity);
            return RestResponse.succeed(entity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return RestResponse.fail("保存失败！");
    }

    @Override
    public RestResponse saveCpvResultEntity(CpvResultEntity entity) {
        try {
            entity.setCpvrId(UUIDGenerator.getUUID());
            entity.setCreateUser(PlatformSessionContext.getUserID());
            entity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
            entity.setDelFlag(YNEnum.N.toString());
            bacInformationRepository.saveCpvResultEntity(entity);
            return RestResponse.succeed(entity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return RestResponse.fail("保存失败！");
    }

    @Override
    public RestResponse updateCpvInfoEntity(CpvInfoEntity entity) {
        try {
            CpvInfoEntity cpviById = bacInformationRepository.getCpviById(entity.getCpviId());
            UpdateUtil.copyNullProperties(cpviById, entity);
            entity.setUpdateUser(PlatformSessionContext.getUserID());
            entity.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
            bacInformationRepository.updateCpvInfoEntity(entity);
            return RestResponse.succeed(entity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return RestResponse.fail("修改失败！");
    }

    private RestResponse psaParameterVerification(int size, List<List<Object>> data) {
        for (int i = 0; i < size; i++) {
            List<Object> objects = data.get(i);
            if (StringUtils.isBlank(objects.get(1).toString()))
                return RestResponse.fail("第" + (i + 2) + "行的{地震动参数}不能为空！");
            if (StringUtils.isBlank(objects.get(2).toString()))
                return RestResponse.fail("第" + (i + 2) + "行的{结构响应参数}不能为空！");
        }
        return RestResponse.succeed();
    }

    private String getNumber(String key) {
        return generationNumberUtil.getGenerationNumber(key);
    }


    @Override
    public RestResponse updateBacInformation(BacInformationVo bacInformationVo) {
        try {
            String type = bacInformationVo.getType();
            if (type.equals(FxfzConstants.CZT_JZWYSX_INFO)) {
                CbvInfoEntity cbvInfo = bacInformationVo.getCbvInfoEntity();
                cbvInfo.setUpdateUser(PlatformSessionContext.getUserID());
                cbvInfo.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
                bacInformationRepository.updateCbv(cbvInfo);
            }
            if (type.equals(FxfzConstants.CZT_ZHJG_INFO)) {
                CbcpInfoEntity cbcInfo = bacInformationVo.getCbcpInfoEntity();
                cbcInfo.setUpdateUser(PlatformSessionContext.getUserID());
                cbcInfo.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
                bacInformationRepository.updateCbc(cbcInfo);
            }
            if (type.equals(FxfzConstants.CZT_GJHNT_INFO)) {
                RcpInformationEntity rcpInfo = bacInformationVo.getRcpInformationEntity();
                rcpInfo.setUpdateUser(PlatformSessionContext.getUserID());
                rcpInfo.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
                bacInformationRepository.updateRcp(rcpInfo);
            }
            if (type.equals(FxfzConstants.CZT_GCJZW_INFO)) {
                HbpInfoEntity hbpInfo = bacInformationVo.getHbpInfoEntity();
                hbpInfo.setUpdateUser(PlatformSessionContext.getUserID());
                hbpInfo.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
                bacInformationRepository.updateHbp(hbpInfo);
            }
            if (type.equals(FxfzConstants.CZT_GLDZ_INFO)) {
                CpvAnalysisEntity cpvInfo = bacInformationVo.getCpvAnalysisEntity();
                cpvInfo.setUpdateUser(PlatformSessionContext.getUserID());
                cpvInfo.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
                bacInformationRepository.updateCpv(cpvInfo);
            }
            return RestResponse.succeed("修改成功!");
        } catch (Exception e) {
            String message = "修改失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    @Override
    public RestResponse deleteBacInformation(String ids, String type, String province) {
        try {
            //先查询数据是否在基础库
            for (String id : ids.split(",")) {
                List<Integer> integers = bacInformationRepository.queryBasicLibraryById(id, province);
                if (integers.get(0) != 0) {
                    return RestResponse.fail("在基础库中的数据不允许删除!");
                }
            }
            boolean result = true;
            if (type.equals(FxfzConstants.CZT_JZWYSX_INFO)) {
                for (String id : ids.split(",")) {
                    result = bacInformationRepository.deleteCbvById(id, province);
                }
            }
            if (type.equals(FxfzConstants.CZT_ZHJG_INFO)) {
                for (String id : ids.split(",")) {
                    // result = bacInformationRepository.deleteCbcById(id);
                    result = bacInformationRepository.deleteCbcbiById(id);
                    if (result) {
                        bacInformationRepository.deleteCbcbDetailById(id);
                    }
                }
            }
            if (type.equals(FxfzConstants.CZT_GJHNT_INFO)) {
                for (String id : ids.split(",")) {
                    result = bacInformationRepository.deleteRcpById(id);
                }
            }
            if (type.equals(FxfzConstants.CZT_GCJZW_INFO)) {
                for (String id : ids.split(",")) {
                    result = bacInformationRepository.deleteHbpById(id);
                }
            }
//            if (type.equals(FxfzConstants.CZT_GLDZ_INFO)) {
//                for (String id : ids.split(",")) {
//                    result = bacInformationRepository.deleteCpvById(id);
//                }
//            }
            if (!result) {
                return RestResponse.fail("删除失败!");
            }
            return RestResponse.succeed("删除成功!");
        } catch (Exception e) {
            String message = "删除失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    @Override
    public RestResponse queryBacInformationById(String id, String type) {
//        BacInformationVo bacInformationVo = new BacInformationVo();
//        try {
//            if (type.equals(FxfzConstants.CZT_JZWYSX_INFO)) {
//                bacInformationVo.setCbvInfoEntity(bacInformationRepository.getCbvById(id));
//            }
//            if (type.equals(FxfzConstants.CZT_ZHJG_INFO)) {
//                bacInformationVo.setCbcpInfoEntity(bacInformationRepository.getCbcById(id));
//            }
//            if (type.equals(FxfzConstants.CZT_GJHNT_INFO)) {
//                bacInformationVo.setRcpInformationEntity(bacInformationRepository.getRpcById(id));
//            }
//            if (type.equals(FxfzConstants.CZT_GCJZW_INFO)) {
//                bacInformationVo.setHbpInfoEntity(bacInformationRepository.getHbpById(id));
//            }
//            if (type.equals(FxfzConstants.CZT_GLDZ_INFO)) {
//                bacInformationVo.setCpvAnalysisEntity(bacInformationRepository.getCpvById(id));
//            }
//            return RestResponse.succeed(bacInformationVo);
//        } catch (Exception e) {
//            String message = "查看失败!";
//            log.error(message, e);
//            return RestResponse.fail(message);
//        }
        return null;
    }

    @Autowired
    private SUserService userService;

    @Autowired
    private SysAreaService areaService;

    @Override
    public RestResponse queryBacInformation(QueryBacInformationVo queryBacInformationVo, HttpServletRequest request) {
        try {
            int page = Integer.parseInt(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int size = Integer.parseInt(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            if (PlatformObjectUtils.isEmpty(queryBacInformationVo.getProvince())) {
                String user = userService.getSUser(PlatformSessionContext.getUserID());
                SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
                String province = areaService.getAreaNameByAreaId(sUser.getProvinceId());
                queryBacInformationVo.setProvince(province);
            }
            return RestResponse.succeed(bacInformationRepository.queryBacInformation(queryBacInformationVo, page, size));
        } catch (NumberFormatException e) {
            String message = "查看失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    @Override
    public CpvInfoEntity getCpvInfoEntityById(String id) {
        return bacInformationRepository.getCpviById(id);
    }

    @Override
    public List<CpvAnalysisEntity> getCpvAnalysisEntityByCpviId(String cpviId) {
        return bacInformationRepository.getCpvAnalysisEntityByCpviId(cpviId);
    }

    @Override
    public List<CpvResultEntity> getCpvResultEntityByCpviId(String cpviId) {
        return bacInformationRepository.getCpvResultEntityByCpviId(cpviId);
    }

    private boolean predict(BigDecimal d) {
        if (d.compareTo(new BigDecimal(100)) == 0) {
            return true;
        }
        return false;
    }

    @Override
    public RestResponse saveBvInformation(CbvInfoVo cbvInfo) {
        try {
            String user = sUserService.getSUser(PlatformSessionContext.getUserID());
            SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
            CbvInfoEntity cbvInfoEntity = cbvInfo.getCbvInfoEntity();
            List<CbvInfoMatrixValueEntity> cbvInfoMatrixValueEntities = cbvInfo.getCbvInfoMatrixValueList();
            String number = "QYDR" + "-" + GenerationNumberUtil.getCityInitials(cbvInfoEntity.getProvince()) + "-" +
                    GenerationNumberUtil.type(cbvInfoEntity.getStructureType(), cbvInfoEntity.getStructureType1()) + "-" +
                    GenerationNumberUtil.getFs(cbvInfoEntity.getFortification()) + "-" + this.getNumber(RedisKeyConstants.CZT_ZHJG_KEY);
            cbvInfoEntity.setCbviId(UUIDGenerator.getUUID());
            cbvInfoEntity.setCreateUser(PlatformSessionContext.getUserID());
            cbvInfoEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
            cbvInfoEntity.setDelFlag(YNEnum.N.toString());
            cbvInfoEntity.setDataType(FxfzConstants.CZT_JZWYSX_INFO);
            cbvInfoEntity.setBasicLibrary(YNEnum.N.toString());
            cbvInfoEntity.setNumber(number);
            cbvInfoEntity.setUserName(sUser.getUserName());
            cbvInfoEntity.setCurveOrMatrix(1);

            cbvInfoMatrixValueEntities.forEach(it -> {
                it.setCbviValueId(UUIDGenerator.getUUID());
                it.setCbviId(cbvInfoEntity.getCbviId());
                it.setCreateUser(PlatformSessionContext.getUserID());
                it.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                it.setDelFlag(YNEnum.N.toString());
                bacInformationRepository.saveBvInformationValue(it);
            });
            bacInformationRepository.saveBvInformation(cbvInfoEntity);
            return RestResponse.succeed("成功!");
        } catch (JsonSyntaxException e) {
            String message = "失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }


    @Override
    public RestResponse uploadSingleBvInformationCurve(MultipartFile file) {
        try {
            ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
            List<Object> title = reader.readRow(0);
            String titleName = "[序号, 极限状态, Mr, βr, ]";
            if (!titleName.equals(title.toString())) {
                return RestResponse.fail("导入失败，请检查表头是否改动");
            }
            List<List<Object>> read = reader.read(1, reader.getRowCount());
            if (read.size() == 0) {
                return RestResponse.fail("导入失败，表格中无数据");
            }
            //数据校验
            RestResponse rs = singleBvInformationCurve(read.size(), read);
            if (rs.getCode() != 200) {
                return RestResponse.fail(rs.getMessage());
            }
            CbvInfoEntity cbvInfoEntity = new CbvInfoEntity();
            for (List<Object> objects : read) {
                switch (objects.get(1).toString()) {
                    case "轻微":
                        cbvInfoEntity.setSdMr(new BigDecimal(objects.get(2).toString()));
                        cbvInfoEntity.setSdBr(new BigDecimal(objects.get(3).toString()));
                    case "中等":
                        cbvInfoEntity.setMdMr(new BigDecimal(objects.get(2).toString()));
                        cbvInfoEntity.setMdBr(new BigDecimal(objects.get(3).toString()));
                    case "严重":
                        cbvInfoEntity.setEdMr(new BigDecimal(objects.get(2).toString()));
                        cbvInfoEntity.setEdBr(new BigDecimal(objects.get(3).toString()));
                    case "倒塌":
                        cbvInfoEntity.setCollapseMr(new BigDecimal(objects.get(2).toString()));
                        cbvInfoEntity.setCollapseBr(new BigDecimal(objects.get(3).toString()));
                }
            }
            return RestResponse.succeed(cbvInfoEntity);
        } catch (Exception e) {
            String message = "导入失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    private RestResponse singleBvInformationCurve(int size, List<List<Object>> data) {
        for (int i = 0; i < size; i++) {
            List<Object> objects = data.get(i);
            if (StringUtils.isBlank(objects.get(1).toString()))
                return RestResponse.fail("第" + (i + 1) + "行的{极限状态}不能为空！");
            if (StringUtils.isBlank(objects.get(2).toString()))
                return RestResponse.fail("第" + (i + 1) + "行的{Mr}不能为空！");
            if (StringUtils.isBlank(objects.get(3).toString()))
                return RestResponse.fail("第" + (i + 1) + "行的{βr}不能为空！");
        }
        return RestResponse.succeed();
    }

    @Override
    public RestResponse uploadBvInformationCurve(MultipartFile file) {
        try {
            String user = sUserService.getSUser(PlatformSessionContext.getUserID());
            SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
            ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
            List<Object> title = reader.readRow(1);
            String titleName = "[序号, 省份, 市, 区/县级, *结构类型, *结构类型, *设防情况, 年代, 用途, 用途, 层数, *起始IM值, *终止IM值, *自增跨度, *极限状态, *Mr, *βr]";
            if (!titleName.equals(title.toString())) {
                return RestResponse.fail("导入失败，请检查表头是否改动");
            }
            List<List<Object>> read = reader.read(2, reader.getRowCount());
            if (read.size() == 0) {
                return RestResponse.fail("导入失败，表格中无数据");
            }
            //数据校验
            RestResponse rs = bvInformationCurve(read.size(), read);
            if (rs.getCode() != 200) {
                return RestResponse.fail(rs.getMessage());
            }
            ArrayList<CbvInfoEntity> dataList = new ArrayList<>();
            for (List<Object> objects : read) {
                CbvInfoEntity cbvInfoEntity = new CbvInfoEntity();
                cbvInfoEntity.setCbviId(UUIDGenerator.getUUID());
                cbvInfoEntity.setProvince(objects.get(1).toString());
                cbvInfoEntity.setCity(objects.get(2).toString());
                cbvInfoEntity.setCounty(objects.get(3).toString());
                cbvInfoEntity.setStructureType(objects.get(4).toString());
                cbvInfoEntity.setStructureType1(objects.get(5).toString());
                cbvInfoEntity.setFortification(objects.get(6).toString());
                cbvInfoEntity.setYears(objects.get(7).toString());
                cbvInfoEntity.setUse0(objects.get(8).toString());
                cbvInfoEntity.setUse1(objects.get(9).toString());
                cbvInfoEntity.setCs(objects.get(10).toString());
                cbvInfoEntity.setStartImValue(new BigDecimal(objects.get(11).toString()));
                cbvInfoEntity.setEndImValue(new BigDecimal(objects.get(12).toString()));
                cbvInfoEntity.setSelfIncreasingSpan(new BigDecimal(objects.get(13).toString()));
                cbvInfoEntity.setLimitState(objects.get(14).toString());
                cbvInfoEntity.setMr(new BigDecimal(objects.get(15).toString()));
                cbvInfoEntity.setBr(new BigDecimal(objects.get(16).toString()));
                cbvInfoEntity.setCreateUser(PlatformSessionContext.getUserID());
                cbvInfoEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                cbvInfoEntity.setUserName(sUser.getUserName());
                cbvInfoEntity.setDelFlag(YNEnum.N.toString());
                cbvInfoEntity.setDataType(FxfzConstants.CZT_JZWYSX_INFO);
                cbvInfoEntity.setCurveOrMatrix(0);
                cbvInfoEntity.setBasicLibrary("0");
                //此字段作为筛选数据使用
                cbvInfoEntity.setOrderField(cbvInfoEntity.getProvince() + "_" + cbvInfoEntity.getCity() + "_" + cbvInfoEntity.getCounty()
                        + "_" + cbvInfoEntity.getUse0() + "_" + cbvInfoEntity.getUse1() + "_" + cbvInfoEntity.getStructureType() + "_" + cbvInfoEntity.getStructureType1()
                        + "_" + cbvInfoEntity.getYears() + "_" + cbvInfoEntity.getCs() + "_" + cbvInfoEntity.getStartImValue() + "_" + cbvInfoEntity.getEndImValue() + "_" + cbvInfoEntity.getSelfIncreasingSpan() + "_" + cbvInfoEntity.getFortification());
                dataList.add(cbvInfoEntity);
            }

            Map<String, List<CbvInfoEntity>> collect = dataList.stream().collect(Collectors.groupingBy(CbvInfoEntity::getOrderField));
            ArrayList<CbvInfoEntity> list = new ArrayList<>();
            collect.forEach((k, v) -> {
                String generationNumber = this.getNumber(RedisKeyConstants.CZT_JZWYSX_KEY);
                String[] split = k.split("_");
                String number = "QYDR" + "-" + GenerationNumberUtil.getCityInitials(split[0]) + "-" +
                        GenerationNumberUtil.type(split[5], split[6]) + "-" +
                        GenerationNumberUtil.getFs(split[12]) + "-" + generationNumber;

                CbvInfoEntity cbvInfoEntity = v.get(0);

                v.parallelStream().forEach(it -> {
                    if (it.getLimitState().equals("轻微")) {
                        cbvInfoEntity.setSdMr(it.getMr());
                        cbvInfoEntity.setSdBr(it.getBr());
                    }
                    if (it.getLimitState().equals("中等")) {
                        cbvInfoEntity.setMdMr(it.getMr());
                        cbvInfoEntity.setMdBr(it.getBr());
                    }
                    if (it.getLimitState().equals("严重")) {
                        cbvInfoEntity.setEdMr(it.getMr());
                        cbvInfoEntity.setEdBr(it.getBr());
                    }
                    if (it.getLimitState().equals("倒塌")) {
                        cbvInfoEntity.setCollapseMr(it.getMr());
                        cbvInfoEntity.setCollapseBr(it.getBr());
                    }
                });
                cbvInfoEntity.setNumber(number);
                list.add(cbvInfoEntity);
            });
            list.parallelStream().forEach(it -> {
                bacInformationRepository.saveBvInformation(it);
                fImCount(it);
            });
            return RestResponse.succeed("导入成功!");
        } catch (Exception e) {
            String message = "导入失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    private RestResponse bvInformationCurve(int size, List<List<Object>> data) {
        for (int i = 0; i < size; i++) {
            List<Object> objects = data.get(i);
            if (StringUtils.isBlank(objects.get(1).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{省份}不能为空！");
            if (StringUtils.isBlank(objects.get(2).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{市}不能为空！");
            if (StringUtils.isBlank(objects.get(3).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{区县}不能为空！");
            if (StringUtils.isBlank(objects.get(4).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{结构类型}不能为空！");
            if (StringUtils.isBlank(objects.get(6).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{设防情况}不能为空！");
            if (StringUtils.isBlank(objects.get(7).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{年代}不能为空！");
            if (StringUtils.isBlank(objects.get(8).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{用途}不能为空！");
            if (StringUtils.isBlank(objects.get(9).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{用途}不能为空！");
            if (StringUtils.isBlank(objects.get(10).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{层数}不能为空！");
            if (StringUtils.isBlank(objects.get(11).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{起始IM值}不能为空！");
            if (StringUtils.isBlank(objects.get(12).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{终止IM值}不能为空！");
            if (StringUtils.isBlank(objects.get(13).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{自增跨度}不能为空！");
            if (StringUtils.isBlank(objects.get(14).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{极限状态}不能为空！");
            if (StringUtils.isBlank(objects.get(15).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{Mr}不能为空！");
            if (StringUtils.isBlank(objects.get(16).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{Br}不能为空！");
        }
        return RestResponse.succeed();
    }

    @Autowired
    private ThreadPoolUtil threadPoolUtil;

    /**
     * fim计算
     */
    public void fImCount(CbvInfoEntity entity) {
        try {
            BigDecimal startImValue = entity.getStartImValue();
//            startImValue = BigDecimal.valueOf(0.01);
            BigDecimal endImValue = entity.getEndImValue();
//            endImValue = BigDecimal.valueOf(2);
            BigDecimal intervalValue = entity.getSelfIncreasingSpan();
//            intervalValue = BigDecimal.valueOf(0.01);
            Map<String, Map<BigDecimal, BigDecimal>> mapMap = new HashMap<>();
            while (startImValue.compareTo(endImValue.add(intervalValue)) < 1) {
                if (startImValue.compareTo(endImValue) > 0) {
                    startImValue = endImValue ;
                }
                BigDecimal a2 = BigDecimal.valueOf(Math.log(startImValue.doubleValue()));
                //起线程
                int threadNum = 4;
                ExecutorService executorService = threadPoolUtil.getFixedThreadPool(threadNum);
                List<Future> futureList = new ArrayList<>();
                for (int j = 0; j < threadNum; j++) {
                    BigDecimal temp = new BigDecimal(0);
                    try {
                        if (j == 0) {
                            BigDecimal subtract = a2.subtract(BigDecimal.valueOf(Math.log(entity.getSdMr().doubleValue())));
                            temp = subtract.divide(entity.getSdBr(), 4,
                                    BigDecimal.ROUND_HALF_UP);
                        } else if (j == 1) {
                            BigDecimal subtract = a2.subtract(BigDecimal.valueOf(Math.log(entity.getMdMr().doubleValue())));
                            temp = subtract.divide(entity.getMdBr(), 4,
                                    BigDecimal.ROUND_HALF_UP);
                        } else if (j == 2) {
                            BigDecimal subtract = a2.subtract(BigDecimal.valueOf(Math.log(entity.getEdMr().doubleValue())));
                            temp = subtract.divide(entity.getEdBr(), 4,
                                    BigDecimal.ROUND_HALF_UP);
                        } else if (j == 3) {
                            BigDecimal subtract = a2.subtract(BigDecimal.valueOf(Math.log(entity.getCollapseMr().doubleValue())));
                            temp = subtract.divide(entity.getCollapseBr(), 4,
                                    BigDecimal.ROUND_HALF_UP);
                        }
                    } catch (ArithmeticException e) {
                        temp = BigDecimal.ZERO;
                    }
                    Callable callable = new ReloadCallable(temp, "signal");
                    Future submit = executorService.submit(callable);
                    futureList.add(submit);
                }
                executorService.shutdown();

                BigDecimal FIM1 = (BigDecimal) futureList.get(0).get();
                BigDecimal FIM2 = (BigDecimal) futureList.get(1).get();
                BigDecimal FIM3 = (BigDecimal) futureList.get(2).get();
                BigDecimal FIM4 = (BigDecimal) futureList.get(3).get();

                Map<BigDecimal, BigDecimal> map = null;
                if (mapMap.containsKey("SD")) {
                    map = mapMap.get("SD");
                } else {
                    map = new TreeMap<>();
                }
                map.put(startImValue, FIM1);
                mapMap.put("SD", map);
                if (mapMap.containsKey("MD")) {
                    map = mapMap.get("MD");
                } else {
                    map = new TreeMap<>();
                }
                map.put(startImValue, FIM2);
                mapMap.put("MD", map);
                if (mapMap.containsKey("ED")) {
                    map = mapMap.get("ED");
                } else {
                    map = new TreeMap<>();
                }
                map.put(startImValue, FIM3);
                mapMap.put("ED", map);
                if (mapMap.containsKey("CD")) {
                    map = mapMap.get("CD");
                } else {
                    map = new TreeMap<>();
                }
                map.put(startImValue, FIM4);
                mapMap.put("CD", map);

                if (startImValue.compareTo(endImValue) == 0) {
                    break;
                }
                startImValue = startImValue.add(intervalValue);
            }
            for (String key : mapMap.keySet()) {
                int sum = 1;
                Map<BigDecimal, BigDecimal> map = mapMap.get(key);
                for (Map.Entry<BigDecimal, BigDecimal> entry : map.entrySet()) {
                    CbvInfoCurveValueEntity cbvInfoCurveValueEntity = new CbvInfoCurveValueEntity();
                    cbvInfoCurveValueEntity.setCbviId(entity.getCbviId());
                    cbvInfoCurveValueEntity.setCurveId(UUIDGenerator.getUUID());
                    cbvInfoCurveValueEntity.setBreakState(key);
                    cbvInfoCurveValueEntity.setSum(sum);
                    cbvInfoCurveValueEntity.setIm(entry.getKey().setScale(4, BigDecimal.ROUND_HALF_UP));
                    cbvInfoCurveValueEntity.setFim(entry.getValue().setScale(4, BigDecimal.ROUND_HALF_UP));
                    cbvInfoCurveValueEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                    cbvInfoCurveValueEntity.setCreateUser(PlatformSessionContext.getUserID());
                    bacInformationRepository.saveCurveValueEntity(cbvInfoCurveValueEntity);
                    sum++;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    class ReloadCallable implements Callable<Object> {
        private BigDecimal value;
        private BigDecimal temp;
        private String type;

        ReloadCallable(BigDecimal value, String type) {
            this.value = value;
            this.type = type;
        }

        ReloadCallable(BigDecimal value, BigDecimal temp, String type) {
            this.type = type;
            this.value = value;
            this.temp = temp;
        }

        @Override
        public Object call() throws Exception {
            if ("signal".equals(type)) {
                return selfCaculate(value);
            } else if ("for".equals(type)) {
                return temp(value, temp);
            } else if ("temp".equals(type)) {
                return fx(value);
            }
            return null;
        }
    }

    private static List<BigDecimal> temp(BigDecimal ret, BigDecimal temp) {
        List<BigDecimal> bList = new ArrayList<>();
        ret = ret.add(BigDecimal.valueOf(0.0001).multiply(fx(temp)));
        temp = temp.add(BigDecimal.valueOf(0.0001));
        bList.add(0, ret);
        bList.add(1, temp);
        return bList;
    }

    /**
     * 计算fai
     *
     * @param u
     */
    public static BigDecimal selfCaculate(BigDecimal u) {
        BigDecimal ret = BigDecimal.valueOf(0);
        if (u.compareTo(BigDecimal.valueOf(-3.89)) < 0) {
            return new BigDecimal(0);
        } else if (u.compareTo(BigDecimal.valueOf(3.89)) > 0) {
            return new BigDecimal(1);
        }
        BigDecimal temp = BigDecimal.valueOf(-3.89);
        while (temp.compareTo(u) < 1) {
            ret = ret.add(BigDecimal.valueOf(0.0001).multiply(fx(temp)));
            temp = temp.add(BigDecimal.valueOf(0.0001));
        }
        return ret;
    }

    private static BigDecimal fx(BigDecimal x) {
        double a = 1.0 / Math.sqrt(Math.PI * 2);
        a = a * Math.pow(Math.E, -0.5 * Math.pow(Double.parseDouble(x.toString()), 2));
        return BigDecimal.valueOf(a);
    }

    @Override
    public RestResponse saveBvInformationCurve(CbvInfoVo cbvInfo) {
        try {
            String user = sUserService.getSUser(PlatformSessionContext.getUserID());
            SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
            CbvInfoEntity cbvInfoEntity = cbvInfo.getCbvInfoEntity();
            String number = "QYDR" + "-" + GenerationNumberUtil.getCityInitials(cbvInfoEntity.getProvince()) + "-" +
                    GenerationNumberUtil.type(cbvInfoEntity.getStructureType(), cbvInfoEntity.getStructureType1()) + "-" +
                    GenerationNumberUtil.getFs(cbvInfoEntity.getFortification()) + "-" + this.getNumber(RedisKeyConstants.CZT_ZHJG_KEY);
            cbvInfoEntity.setCbviId(UUIDGenerator.getUUID());
            cbvInfoEntity.setCreateUser(PlatformSessionContext.getUserID());
            cbvInfoEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
            cbvInfoEntity.setDelFlag(YNEnum.N.toString());
            cbvInfoEntity.setDataType(FxfzConstants.CZT_JZWYSX_INFO);
            cbvInfoEntity.setBasicLibrary(YNEnum.N.toString());
            cbvInfoEntity.setNumber(number);
            cbvInfoEntity.setUserName(sUser.getUserName());
            cbvInfoEntity.setCurveOrMatrix(0);

            bacInformationRepository.saveBvInformation(cbvInfoEntity);

            List<CbvInfoValueEntity> cbvInfoValueList = cbvInfo.getCbvInfoValueList();

            for (CbvInfoValueEntity entity : cbvInfoValueList) {
                cbvInfoEntity.setSdMr(entity.getSdMr());
                cbvInfoEntity.setSdBr(entity.getSdBr());
                cbvInfoEntity.setMdMr(entity.getMdMr());
                cbvInfoEntity.setMdBr(entity.getMdBr());
                cbvInfoEntity.setEdMr(entity.getEdMr());
                cbvInfoEntity.setEdBr(entity.getEdBr());
                cbvInfoEntity.setCollapseMr(entity.getCollapseMr());
                cbvInfoEntity.setCollapseBr(entity.getCollapseBr());
            }
            //计算Fim并入库
            fImCount(cbvInfoEntity);
            return RestResponse.succeed("成功!");
        } catch (JsonSyntaxException e) {
            String message = "失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    @Override
    public RestResponse moveBasicLibrary(List<CustomVulnerabilityParam> paramList) {
        ArrayList<QueryBasicVo> voList = new ArrayList<>();
        for (CustomVulnerabilityParam param : paramList) {
            List<QueryBasicVo> list = bacInformationRepository.queryBasicLibrary(param);
            if(param.getOperate().equals("1")){
                if (PlatformObjectUtils.isNotEmpty(list)) {
                    voList.addAll(list);
                    continue;
                }
            }
            String dataType = param.getDataType();
            if (dataType.equals(FxfzConstants.CZT_JZWYSX_INFO)) {
                if (param.getOperate().equals("0")) {
                    bacInformationRepository.moveCbvBasicLibraryById(param.getId(), param.getOperate(), param.getProvince());
                } else {
                    bacInformationRepository.moveCbvBasicLibraryById(param.getId(), param.getOperate(), param.getProvince());
                }
            }

            if (dataType.equals(FxfzConstants.CZT_ZHJG_INFO)) {
                if (param.getOperate().equals("0")) {
                    pobStructureRepository.moveBasicLibraryById(param.getId(), param.getOperate());
                } else {
                    pobStructureRepository.moveBasicLibraryById(param.getId(), param.getOperate());
                }
            }

            if (dataType.equals(FxfzConstants.CZT_GJHNT_INFO)) {
                if (param.getOperate().equals("0")) {
                    rcpInformationRepository.moveBasicLibraryById(param.getId(), param.getOperate());
                } else {
                    rcpInformationRepository.moveBasicLibraryById(param.getId(), param.getOperate());
                }
            }

            if (dataType.equals(FxfzConstants.CZT_GCJZW_INFO)) {
                if (param.getOperate().equals("0")) {
                    fshBuildingsRepository.moveBasicLibraryById(param.getId(), param.getOperate());
                } else {
                    fshBuildingsRepository.moveBasicLibraryById(param.getId(), param.getOperate());
                }
            }

            if (dataType.equals(FxfzConstants.CZT_GLDZ_INFO)) {
                if (param.getOperate().equals("0")) {
                    psvAnalysisRepository.moveBasicLibrary(param.getId(), param.getOperate());
                } else {
                    psvAnalysisRepository.moveBasicLibrary(param.getId(), param.getOperate());
                }
            }
        }
        return RestResponse.succeed(voList);
    }

    @Override
    public RestResponse getBacInfoByNumber(String id, String province) {
        try {
            HashMap<String, Object> map = new HashMap<>();
            CbvInfoEntity cbvInfoEntity = bacInformationRepository.getCbvInfoById(id, province);
            map.put("entity", cbvInfoEntity);
            if (PlatformObjectUtils.isNotEmpty(cbvInfoEntity)) {
                if (cbvInfoEntity.getCurveOrMatrix() == 1) {
                    //矩阵
                    List<CbvInfoMatrixValueEntity> matrixList = bacInformationRepository.getMatrixByProjectId(id);
                    matrixList.sort((o1, o2) -> {
                        Integer i1 = Integer.parseInt(o1.getIntensity().substring(0, o1.getIntensity().length() - 1));
                        Integer i2 = Integer.parseInt(o2.getIntensity().substring(0, o2.getIntensity().length() - 1));
                        return i1.compareTo(i2);
                    });
                    map.put("matrix", matrixList);
                } else {
                    List<CbvInfoCurveValueEntity> curveList = bacInformationRepository.getCbvInfoValueByProjectId(id);
                    map.put("curve", curveList);
                }
            }
            return RestResponse.succeed(map);
        } catch (Exception e) {
            String message = "失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    @Override
    public void exportExcel(HttpServletResponse response, String id, String type) {
        try {
            if (type.equals(FxfzConstants.CZT_ZHJG_INFO)) {
                //砖混
                ArrayList<CbcbInfoVo> dataList = new ArrayList<>();
                CbcbInfoEntity cbcbInfoEntity = bacInformationRepository.getCbcbiById(id);
                List<CbcbDetailEntity> detailList = bacInformationRepository.getCbcbdById(id);
                for (CbcbDetailEntity detailEntity : detailList) {
                    CbcbInfoVo cbcbInfoVo = new CbcbInfoVo();
                    BeanUtil.copyPropertiesIgnoreEmpty(cbcbInfoEntity, cbcbInfoVo);
                    BeanUtil.copyPropertiesIgnoreEmpty(detailEntity, cbcbInfoVo);
                    dataList.add(cbcbInfoVo);
                }
                FileUtil.exportExcel(dataList, "砖混结构参数信息", "砖混结构参数信息", CbcbInfoVo.class, "砖混结构参数信息.xls", response);
            }
            if (type.equals(FxfzConstants.CZT_GCJZW_INFO)) {
                ArrayList<HbpInfoVo> dataList = new ArrayList<>();
                HbpInfoEntity hbpEntity = bacInformationRepository.getHbpById(id);
                HbpInfoVo hbpInfoVo = new HbpInfoVo();
                BeanUtil.copyPropertiesIgnoreEmpty(hbpEntity, hbpInfoVo);
                dataList.add(hbpInfoVo);
                FileUtil.exportExcel(dataList, "高层建筑参数信息", "高层建筑参数信息", HbpInfoVo.class, "高层建筑参数信息.xls", response);
            }
            if (type.equals(FxfzConstants.CZT_GJHNT_INFO)) {
                List<ExportRcpExcelSheet1Vo> list = bacInformationRepository.getRcpInformationById(id);
                list.forEach(it->{
                    String name = CorrectionCiEnum.getByCode(Integer.parseInt(it.getCiType4Value()));
                    it.setCiType4Value(name);
                    it.setCiType1Value(it.getCiType1Value().equals("1")?"不满足":"满足");
                    it.setCiType2Value(it.getCiType2Value().equals("0")?"是":"否");
                    it.setCiType3Value(it.getCiType3Value().equals("0")?"满足":"不满足");
                });
                FileUtil.exportExcel(list, "钢筋混凝土参数信息", "钢筋混凝土参数信息", ExportRcpExcelSheet1Vo.class, "钢筋混凝土参数信息.xls", response);
//                FileUtil.exportExcel(rcpInformationById, "钢筋混凝土参数信息", "钢筋混凝土参数信息", RcpInformationVo.class, "钢筋混凝土参数信息.xls", response);
//                Map<String, String> headNameMap = new LinkedHashMap<>();
//                headNameMap.put("province", "省");
//                headNameMap.put("city", "市");
//                headNameMap.put("county", "区/县级");
//                headNameMap.put("purpose", "用途");
//                headNameMap.put("purpose1", "用途");
//                headNameMap.put("structureType", "结构类型");
//                headNameMap.put("structureType1", "结构类型");
//                headNameMap.put("years", "年代");
//                headNameMap.put("fortification", "设防情况");
//                headNameMap.put("cs", "层数");
//                headNameMap.put("pillarCode", "柱编号");
//                headNameMap.put("trussSpacing", "每榀间距（m）");
//                headNameMap.put("span", "跨度");
//                headNameMap.put("floorNum", "层号");
//                headNameMap.put("pillarHeight", "柱净高Hn");
//                headNameMap.put("pillarSectionWidth", "柱截面宽b(mm)");
//                headNameMap.put("pillarSectionHeight", "柱截面高h(mm)");
//                headNameMap.put("fyk", "纵筋fyk");
//                headNameMap.put("portraitSectionalArea", "纵向受拉筋总截面积As");
//                headNameMap.put("h0", "柱截面有效高");
//                headNameMap.put("fck", "混凝土抗压强度标准值fck");
//                headNameMap.put("bk", "界限受压区高度ζbk");
//                headNameMap.put("totalSpan", "总跨度");
//                headNameMap.put("distance", "受压筋合理点距受压边缘的距离as");
//                headNameMap.put("boardThickness", "板厚");
//                headNameMap.put("concreteCode", "砼标号");
//                headNameMap.put("fvk", "fvk");
//                headNameMap.put("spacing", "箍筋间距s");
//                headNameMap.put("sectionalArea", "箍筋截面积Asv");
//                headNameMap.put("ash", "剪力墙Ash");
//                headNameMap.put("s2", "剪力墙箍筋间距 S2");
//                headNameMap.put("fyvk", "剪力墙箍筋标准值");
//                headNameMap.put("am", "砖填充墙水平截面面积");
//                headNameMap.put("hasTcq", "两侧是否有填充墙");
//                headNameMap.put("en", "砌体强度的正压力影响系数");
//                headNameMap.put("fvkStrength", "砖墙的抗剪强度标准值fvk");
//                headNameMap.put("wallSectionalArea", "抗震墙的截面积Aw");
//                headNameMap.put("sectionalAsh", "水平钢筋截面面积Ash");
//                headNameMap.put("jkb", "抗震墙的计算剪跨比   λ");
//                headNameMap.put("floorHeight", "层高");
//                headNameMap.put("liveLoad", "活荷载");
//                headNameMap.put("pillarPosition", "边柱/中柱");
//                headNameMap.put("beamNum", "梁编号");
//                headNameMap.put("beamHeigth", "梁高");
//                headNameMap.put("beamSectionWidth", "梁截面高");
//                headNameMap.put("beamSectionHeight", "梁截面宽");
//                headNameMap.put("el", "梁混凝土弹性模具");
//                byte[] excelBytes = ExcelUtils.toExcelMergeCell(list, headNameMap, 1, new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 1);
//                response.setContentType("application/vnd.ms-excel");
//                response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("钢筋混凝土数据.xls", "utf-8"));
//                response.getOutputStream().write(excelBytes);
//                response.getOutputStream().flush();
//                response.getOutputStream().close();
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public RestResponse updateBuildingArea(BuildingVulnerabilityParam param) {
        try {
            CbvInfoEntity entity = bacInformationRepository.getCbvInfoById(param.getCbviId(), param.getProvince());
            CbvInfoEntity newEntity = paramToEntity(param);
            bacInformationRepository.updateCbv(newEntity);
            if (entity.getCurveOrMatrix() == 1) {
                List<MatrixParam> matrixParam = param.getMatrixParam();
                for (MatrixParam matrixEntity : matrixParam) {
                    BigDecimal value = matrixEntity.getBasicallyIntact().add(matrixEntity.getMinorDamage())
                            .add(matrixEntity.getModerateDamage()).add(matrixEntity.getSeriousDamage())
                            .add(matrixEntity.getCollapse()).setScale(1, RoundingMode.HALF_UP);
                    if (!predict(value)) {
                        return RestResponse.fail("每个烈度下破坏状态总和应为100");
                    }
                    bacInformationRepository.updateMatrixById(matrixParamToEntity(matrixEntity));
                }
            } //TODO  修改曲线数据
            return RestResponse.succeed("修改成功");
        } catch (Exception e) {
            String message = "修改失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }

    private CbvInfoMatrixValueEntity matrixParamToEntity(MatrixParam param) {
        CbvInfoMatrixValueEntity entity = new CbvInfoMatrixValueEntity();
        entity.setCbviValueId(param.getCbviValueId());
        entity.setBasicallyIntact(param.getBasicallyIntact());
        entity.setMinorDamage(param.getMinorDamage());
        entity.setModerateDamage(param.getModerateDamage());
        entity.setSeriousDamage(param.getSeriousDamage());
        entity.setCollapse(param.getCollapse());
        entity.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
        entity.setUpdateUser(PlatformSessionContext.getUserID());
        return entity;
    }

    private CbvInfoEntity paramToEntity(BuildingVulnerabilityParam param) {
        CbvInfoEntity entity = new CbvInfoEntity();
        entity.setCbviId(param.getCbviId());
        entity.setUse0(param.getUse0());
        entity.setUse1(param.getUse1());
        entity.setCs(param.getCs());
        entity.setYears(param.getYears());
        entity.setInfo(param.getInfo());
        entity.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
        entity.setUpdateUser(PlatformSessionContext.getUserID());
        return entity;
    }

    @Override
    public boolean confirmMoveIn(ConfirmMoveIdParam param) {
        List<CustomVulnerabilityParam> oldData = param.getOldData();
        oldData.forEach(it->{
            it.setGrouping(it.getProvince()+"-"+it.getCity()+"-"+it.getCounty()+"-"+it.getStructureType()+"-"+it.getStructureType1()+"-"+it.getYears()+"-"+it.getFortification()
            +"-"+it.getUse0()+"-"+it.getUse1()+"-"+it.getCs());
        });
        Map<String, List<CustomVulnerabilityParam>> collect = oldData.stream().collect(Collectors.groupingBy(CustomVulnerabilityParam::getGrouping));
        if(collect.size()!=oldData.size()){
            return false;
        }
        List<MoveInParam> newData = param.getNewData();
        newData.forEach(it->{
            String dataType = it.getDataType();
            if (dataType.equals(FxfzConstants.CZT_JZWYSX_INFO)) {
                bacInformationRepository.moveCbvBasicLibraryById(it.getId(),"0", it.getProvince());
            }

            if (dataType.equals(FxfzConstants.CZT_ZHJG_INFO)) {
                pobStructureRepository.moveBasicLibraryById(it.getId(), "0");
            }

            if (dataType.equals(FxfzConstants.CZT_GJHNT_INFO)) {
                rcpInformationRepository.moveBasicLibraryById(it.getId(), "0");
            }

            if (dataType.equals(FxfzConstants.CZT_GCJZW_INFO)) {
                fshBuildingsRepository.moveBasicLibraryById(it.getId(), "0");
            }

            if (dataType.equals(FxfzConstants.CZT_GLDZ_INFO)) {
                psvAnalysisRepository.moveBasicLibrary(it.getId(), "0");
            }
        });

        oldData.forEach(it -> {
            String dataType = it.getDataType();
            if (dataType.equals(FxfzConstants.CZT_JZWYSX_INFO)) {
                bacInformationRepository.moveCbvBasicLibraryById(it.getId(),"1", it.getProvince());
            }
            if (dataType.equals(FxfzConstants.CZT_ZHJG_INFO)) {
                pobStructureRepository.moveBasicLibraryById(it.getId(), "1");
            }
            if (dataType.equals(FxfzConstants.CZT_GJHNT_INFO)) {
                rcpInformationRepository.moveBasicLibraryById(it.getId(), "1");
            }
            if (dataType.equals(FxfzConstants.CZT_GCJZW_INFO)) {
                fshBuildingsRepository.moveBasicLibraryById(it.getId(), "1");
            }
            if (dataType.equals(FxfzConstants.CZT_GLDZ_INFO)) {
                psvAnalysisRepository.moveBasicLibrary(it.getId(), "1");
            }
        });
        return true;
    }
}